what's wrong with my code?

there is something wrong with my code, but i can't figure out what it is.  the following funciton is supposed to read in the
autoexec.bat file into a character array called largebuf.  the problem seems to be occurring in th esecond while loop.  it attempts to find the end of the text in the buffer, but then the contents in the buffer vanish!  what's going on?

void writeAutoexec(int mode,int x) {
char largebuf[1500];
//char smallbuf[50];
int j=1;
fstream filebuf ("c:\\autoexec.bat", ios::in | ios::out);
if (mode==1) {
      while (!filebuf.eof())  {        //read the file into largebuf
    while (largebuf[j]!=NULL) {       //find the end of the buffer
          cout<<largebuf; }
    for (int i=j;i > x+1;i--) {       //this should insert 2 spaces for the 16 to be inserted
          largebuf[i] = largebuf[i-1];   //that way, the change can be made no matter where the path statement is
        largebuf[i-1] = largebuf[i-2]; //in the document
    largebuf[x+8] = '1';     //the line change
    largebuf[x+9] = '6';
    } //end if
Who is Participating?
alexoConnect With a Mentor Commented:
while (!filebuf.eof()) {
    filebuf.getline(largebuf,sizeof(largebuf)); // This reads one line.  Next iteration overrites it

istream& getline( char* pch, int nCount, char delim = '\n' );

Your getline() only reads up to the next '\n'.  Add a delimiter ('\0') instead of using the default one.
What do you mean Vanish? I run your code, it seems everything is OK.
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Each iteration reads another line and overrites the previous one.
Sure, if you want to treat data to the every line you read in, you should put all the codes in the first while loop.
tetsuoAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.