1 2 3 4 5 6 7 8 9 10

Review of fgets() and command line args.

To aid in input/output of strings we have the fgets()

char* fgets (char* line, int maximum, FILE* fp);

Let us assume that fpcorrectly points to an open file. However if we are now at the end of that file, then fgets will return NULL, indicating that an EOF was read. Otherwise fgetsreads the next line of input (including the newline) from file fp into the character array line, but no more than maximum-1characters will be read! The resulting string (in array line) is terminated with '\0'.

Avoid the functions gets() and puts() on stdin and stdout

Command line arguments

use of int main (int argc, char* argv[]);

Imagine we want to write a program revl which reverses every line in a file whose name is specified in the command line. Thus instead of invoking as
revl <datafile
taking input from stdin, we want to type
revl datafile

4 February, 1998

9

Copyright University of Alberta