Solved

maximum length reading on one line

Posted on 2004-10-05
11
171 Views
Last Modified: 2012-05-05
My program reads input file and writes to output file, but it only writes 250 char length in one line and then writes the rest of chars to the second line.

How can I fix that to make my program writes all the chars to one line ?

or I should ask this way : whats the maximum char length I can have on one line ?

Thanks
0
Comment
Question by:justinY
  • 5
  • 4
  • 2
11 Comments
 
LVL 11

Expert Comment

by:griessh
ID: 12230790
Hi justinY,

Please show us your code for the read/write operations.

======
Werner
0
 

Author Comment

by:justinY
ID: 12230948
the following is my code. It works well with short output file.
But with this long output length. It writes first 250 char length onto one line and writes the rest chars to next line.

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdio>

using namespace std;

const int MaxSize=1024;

////////////////////////////////////////////////////////////
// Custom version of strtok(), fixing empty field problem
////////////////////////////////////////////////////////////
char* MyStrTok(char* text, const char del)
{
    static char *curTok = NULL;
    char *result = NULL;
    if ( text != NULL )
    {
        curTok = text;
    }
    result = curTok;
    if ( curTok != NULL )
    {
        curTok = ::strchr(curTok, del);
        if ( curTok != NULL ) *curTok++ = 0;
    }

    return result;
};

//////////////////////////////////////////
// Remove delimiter  
//////////////////////////////////////////
void removeChar(char* src, char delim )
{
      int i=0,j=0;
      char buf[MaxSize];
      while (src[i] != '\0' )
      {
            if (src[i] == delim)
            {
                  i++;
                  continue;
            }
            buf[j++]=src[i];
            i++;
      }
      buf[j] = '\0';
      strcpy(src,buf);
};

///////////////////////////////
//
// main
//
///////////////////////////////
main(int arc, char *arv[])
{

      ifstream fin("test.csv");
      ofstream fout("fout.txt");
      char row_read[512];
      char row_elem[100][100];
      int i = 0;
      int isFirstLine = 0;

      ///////////////////////////////////////////////////////////////////
      // for each line of file  
      // assume there are 35 columns in each row in file fin.txt
      ///////////////////////////////////////////////////////////////////
      while( fin.getline( row_read, sizeof( row_read ) ) )
      {
            if (isFirstLine ==0 )
            {
                  isFirstLine = 1;
                  continue;
            }
            //////////////////////////////////////////
            // parse string with ","
            //////////////////////////////////////////
            char *token = MyStrTok( row_read, ',' );
            
            while( token != NULL )
            {
                        ///////////////////////////////////////////////////////////
                        // strim '"', '=' etc.. in the fields
                        //////////////////////////////////////////////////////////
                  /*
                         char intrBuf[MaxSize];
                         strcpy(intrBuf,token);
                         removeChar(intrBuf,'=');      
                         removeChar(intrBuf,'"');
                        
                        strcpy(row_elem[i], intrBuf );
                  */      
                        strcpy(row_elem[i], token);
                        /* Get next token: */
                        token = MyStrTok( NULL, ',' );
                        i++;
            } // end of while

      
      //////////////////////////////////////////////////////////////////////
      // output to file, first colmn replaced with value from reference file
      //////////////////////////////////////////////////////////////////////
                 fout<<setw(9)<< row_elem[0]
                      <<setw(2)  << "US"
                     <<setw(1)      << " "
                      <<setw(2)      << row_elem[3]
                       <<setw(4)<< row_elem[4]
            <<setw(3)      << " "
            <<setw(4)      << " "
            <<setw(4)      << " "
            <<setw(2)      << row_elem[8]
            <<setw(2)      << row_elem[9]
            <<setw(2)      << row_elem[10]
            <<setw(2)      << row_elem[11]
            <<setw(3)      << row_elem[12]
            <<setw(3)      << row_elem[13]
            <<setw(60)      << row_elem[14]
            <<setw(5)      << row_elem[15]
            <<setw(15)      << row_elem[16]
            <<setw(1)      << "Y"
            <<setw(6)      << row_elem[0]
            <<setw(1)      << "S"
            <<setw(1)      << "S"
            <<setw(1)      << "Y"
            <<setw(1)      << "Y"
            <<setw(1)      << "Y"
            <<setw(1)      << "Y"
            <<setw(2)      << " "
            <<setw(15)      << row_elem[26]
            <<setw(40)      << row_elem[27]
            <<setw(9)      << " "
            <<setw(9)      << " "
            <<setw(2)      << "NA"
            <<setw(16)      << row_elem[31]
            <<setw(1)      << "N"
            <<setw(16)      << row_elem[33]
            <<setw(1)      << "N"
            <<setw(1)      << "N"
            <<setw(1)      << "Y"
            <<setw(1)      << "N"
            <<setw(1)      << "S"
            <<setw(1)      << "N"
            <<setw(5)      << row_elem[40]
            <<setw(1)      << "N"
            <<setw(5)      << row_elem[42]
            <<setw(1)      << "N"
            <<setw(5)      << " "
            <<setw(5)      << " "
            <<setw(1)      << "N"
            <<setw(3)      << "N"
            <<setw(10)      << row_elem[48]
            <<setw(20)      << " "
            <<setw(1)      << row_elem[50]
            <<setw(16)      << row_elem[51]
            <<setw(1)      << "N"
            <<setw(1)      << "N"
      
      <<endl;

      i=0;
} // end of while

return 0;
}
0
 

Author Comment

by:justinY
ID: 12231694
I should say this way:
on my fout.txt file, It writes first 250 ( or less than 250 ) char length onto one line and writes the rest chars to next line.
0
 

Author Comment

by:justinY
ID: 12231813
Never Mind guys. False alarm. It has something to do with the monitor settings.
I opened this same file on different monitors. One flat panel gives me displaying all on one line. But my big old one gives me two lines.
0
 
LVL 11

Expert Comment

by:griessh
ID: 12232991
Good to hear that you solved it. Ask Community Services to refund your points :-)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 9

Accepted Solution

by:
zaghaghi earned 125 total points
ID: 12236896
hi,
your problem doesn't relate to your monitor, it's just about the editor you use to view the file.

have a good programming day;
0
 

Author Comment

by:justinY
ID: 12237757
zaghaghi, I am more than happy to hear more from you about the editor. Can you kindly give me details ? thanks
0
 
LVL 11

Expert Comment

by:griessh
ID: 12238668
He only wants to tell you that depending on which editor you use it may be possible to have different settings for the length of a line. But since we don't know OS/Editor you are using there is not much more to say.
0
 

Author Comment

by:justinY
ID: 12240161
I am using windows2000 professional and wordpad.
0
 
LVL 11

Expert Comment

by:griessh
ID: 12240468
In View->Options you can set word wrapping. Set it to 'no wrap' and it will show real lines.
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 12285784
in some editors -likes 'word pad' that you use for viewing text files- the "no wrap" option is off by default and your lines wraps in the editor, so you must on this option for your editor.

have a good programming day.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now