c++ - Skipping text file lines on reiteration of loop -


i have loop reads first 9 lines of text file array , makes appropriate use of it. on each additional pass skip 9 lines of text file , overwrite array there. (each section of 9 lines has same type of information)

the problem can't seem skip. have variable increments 9 each time there pass, number of 9 part sections, variable generated measuring lines of text file.

i thought simplest approach increase variable in loop current value of lines want skip, either didn't anything, crashed program, or made output jumbled, depending on how approached it.

this area of text passing information text file 2d array (and removing white space)

for (int x = (0); x < board_size + 1; ++x) {     (int y = 0; y < board_size; ++y)     {         // initializing z because that's not possible input file.         // if appears wrong.         char point = 'z';          if (!file.get(point))             cout << "there seems problem file." << x << "," << y << endl;          if (isblank(point))         {             // without this, spit out spaces every other character of array             --y;          }         else         {             chessboards[x][y] = point;         }     } } 

as written right now, program works, , produces number of tables equal number of tables in file, prints onto screen exact copy of first table each pass.

you can make use of fgetpos save point in file first 9 lines end.

then, on next loop, can use fsetpos retreive position of text file.

here how it:

  • first declare variable store position. type used fpos_t
  • then @ point loop reaches end of 9th line, use getpos save position of file.
  • you can retrieve position using fsetpos , continue previous loop has left off

    fpos_t pos;

    fgetpos(fp, &pos); // save position

    fsetpos(fp, &pos); // restore position saved


Comments