[Courses] [C] Lesson 13: exc1 answer, problem on exc2

Lorne Gutz lgutz at vistar.ca
Fri Dec 6 09:51:21 EST 2002


Take a look at the man page on perror.  It is a very
useful function when dealing with system errors.  It
also saves a bit of time and effort once you have it
mastered.

cheers
Lorne


>
>     fd = open(argv[1], O_RDONLY);
>     if(errno == ENOENT) {
>         fputs("Error: No such file by that name.\n", stderr);
>         return -1;
>     }
>     file = fdopen(fd, "r");
>
>     while(input != EOF) {
>         input = getc(file);        
>         if(input == 10) number_of_lines++;
>     }
>
>     printf("There were %i lines in %s\n", number_of_lines, argv[1]);
>
>     return 0;
> }
> /********** END **********/
>




More information about the Courses mailing list