printf vs fprintf
Gregory Conway
gregory at ritcsh.UUCP
Tue May 17 10:57:12 AEST 1988
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. ;-)
--
================================================================================
Gregory Conway at Computer Science House UUCP: ...rochester!ritcv!ritcsh!gregory
Rochester Institute of Technology, Rochester, NY
"I got an allergy to Perrier, daylight, and responsibility", Marillion
More information about the Comp.lang.c
mailing list