Hi.. How do I skip the first line of a text file. I am not using getline() so I think I cannot use ignore() function. Is there any other way to ignore first line ?

.................
FILE *in;
         char line[1000];
         char *token;
         in = fopen(argv[1],"rt+");
         if( in == NULL) exit(1);
 int i=0; 
 while(! feof(in)) {
         
         //in.ignore(1000, '\n');
//         std::in.ignore ( 1000, '\n' );               
         fgets(line, 1000, in);
.................................

Thanks

You could try this:

FILE *in;
    char line[1000];
    char *token;
    in = fopen(argv[1],"rt+");
    if ( in == NULL) exit(1);
    int i=0;
    // Read the first line... move the file pointer to
    // point to the end of the first line. Note that the
    // definition for end-of-line is the '\n' character.
    fgets(line, 1000, in);
    while (! feof(in))
    {

        // in.ignore(1000, '\n');
        // std::in.ignore ( 1000, '\n' );
        fgets(line, 1000, in);
        cerr << line << endl;
    }

Hope this helped!

Edit: I mean the same thing as what Ancient Dragon said in his post... He answered as I was typing this...

Edited 7 Years Ago by amrith92: n/a

You could try this:

fgets(line, 1000, in);
    while (! feof(in))
    {
        // ...
    }

Why it's bad to use feof() to control a loop

[edit]I think the "rt+" mode is a nonstandard extension meaning "r+" .

[edit]And it might be preferable to do

fgets(line, sizeof line, in);

instead of

fgets(line, 1000, in);

(Preferred by me at least. :P)

Edited 7 Years Ago by Dave Sinkula: n/a

This question has already been answered. Start a new discussion instead.