Thanks a lot. it worked fine
Pushparaj

On Wed, Apr 14, 2010 at 5:33 PM, Mohit Singh <[email protected]> wrote:

> you can use an infinite loop and use feof in an if statement
> immediately after your input functions read from the file. now you can
> break from the loop before processing the last line twice.
>
> #include <stdio.h>
>
> int main(){
>         char buffer[100];
>        FILE *infile = NULL;
>         int start;
>        int end;
>        int cost;
>        int count = 0;
>         char r1[100];
>        char r2[100];
>        char r3[100];
>        char c;
>
>        infile = fopen("tester.txt", "r");
>
>         for(;;){
>                fgets(buffer, 100, infile);
>                if(!feof(infile)) {
>                         sscanf(buffer, "%c %s %s %s", &c, r1, r2, r3);
>                         printf("%c %s %s %s\n", c, r1, r2, r3);
>                        printf("count = %d\n", ++count);
>                }
>                else
>                        break;
>        }
>        fclose(infile);
>        return 0;
> }
>
>
> this code works fine.
>
> --
> Mohit Singh
>
> GNU/Linux User Group - Meerut
>
> --
> l...@iitd - http://tinyurl.com/ycueutm
>
> To unsubscribe, reply using "remove me" as the subject.
>

-- 
l...@iitd - http://tinyurl.com/ycueutm

Reply via email to