fprintf
- Use fprintf(FILE *, char *format, ...) to write to files.
It works just like printf or sprintf -- in fact, all
printf usually does is call fprintf( stdout, ... ).
- The three files stdin, stdout, and stderr
are predefined for you in stdio.h. By default, stdin
is the keyboard, and stdout and stderr are both the
console monitor.
- It is a good idea to write error messages to stderr and not to
stdout. Why? Because programs frequently have their
standard output redirected to another file or program. If you
cat foobar > mojo and their is an error opening foobar,
then you want to hear about it on the console, not in mojo.
- You can't write to files opened for only reading (like stdin)
or read from files opened only for writing (like stderr or
stdout).
Next Slide