Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

maximum length reading on one line

Posted on 2004-10-05
11
196 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

790 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