printf vs fprintf

Pete Holsberg pjh at mccc.UUCP
Wed May 18 06:09:10 AEST 1988


In article <2454 at ritcsh.UUCP> gregory at ritcsh.UUCP (Gregory Conway) writes:
...An interesting point came to mind as I was working today.  I thought I might
...share it with those of you who are (or know someone who is) learning the
...C language.  It seems to me that a great deal of confusion could be saved
...when learning printf, scanf, fprintf, fscanf, sprintf, and sscanf.  The
...point is really simple, don't use printf and scanf.  Use, instead, 
...fprintf (stdout, "....") and fscanf (stdin, "....", &whatever).  Why, you
...ask??  Well, if you think about it, scanf and printf are really special 
...cases of fscanf and fprintf.  The mental correlation is easier if you remember
...you always operate on an IO path, represented by some file.  (stdin and stdout
...are just standard file, right? - hence Fscanf and Fprintf)  Then, when the
...user wants to use sprintf and sscanf, he or she need only remember the the
..."IO path" is a stream, a buffer is you will.  After a person has a complete
...understanding of how all this fits together, he or she could easily use the
...shorter, easier scanf and printf.  Does anyone else think this seems like a 
...good way to learn the rudiments of IO in C??  Flames are welcome.   ;-)

But that adds an incredible burden to the beginner -- thinking about
streams and the additional xprintf/scanf stuff in addition to getting
used to the notation of C.  No flame here, but I do think it's a bad
idea.  At the end of the course, of course, one admits that
printf()/scanf() are special cases of fprintf()/fscanf() -- of course!  :-)



More information about the Comp.lang.c mailing list