how do I skip 3 header lines

Hi experts,

My file has 3 header lines which I want to skip. How can I do that ?

I have the followinfs to skip one header line:

int isFirstLine=0;
if (isFirstLine == 0)
{
    isFirstLine = 1;
    continue;
}

Please advise how to skip 3 header lines. Thanks
justinYAsked:
Who is Participating?
 
VolatileVoidConnect With a Mentor Commented:
Using fgets:
FILE * f = fopen ("NameOfFile.txt", "r+t");
if (!f) {
  printf ("Could not open file?\n");
  exit (1);
} else {
  char someBigBuffer [4096];
  for (int i = 0; i < 3; i++)
    fgets (someBigBuffer, 4096, f);
}

This will work if it's a text file. If you wanna skip 3 "headers" and the "headers" are of constant size (say you have something like this):
struct FHeader {
  char Name[36];
  int something;
  int somethingElse;
}

You could:
FILE * f = fopen ("NameOfFile", "r+b");
if (!f) {
  printf ("Could not open file?\n");
  exit (1);
} else {
  fseek (f, sizeof (FHeader)*3, SEEK_SET);
}

0
 
imladrisCommented:
It might be simpler to simply read the first three lines at the very start, and discard them; rather than trying to handle it all in the same loop.

Psuedo code wise:

open file
for three iterations
     read line

// now process file
while not end of file
   read line
   process it

0
 
imladrisCommented:
Did either of those answers help?

If so, it is time to select one and grade it.

If not, perhaps a clarifying question would help.....
0
All Courses

From novice to tech pro — start learning today.