Solved

maximum length reading on one line

Posted on 2004-10-05
11
189 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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
 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

777 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