why?
why?
To put a line to a file stream. Duh!
Quzah.
Hope is the first step on the road to disappointment.
To print a line of text to the screen, you might want to use it instead of puts() because it doesn't append a newline.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
puts() appends a newline.
That was my point.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Thanks for the answers but to make the questions more clear.Why not use the conventional printf.BTW Quzah i dont understand what you said
Because printf always goes to stdout, but fputs can go to any file, of course.
Now a better question might be "why use fputs instead of fprintf?" and the answer to that is, it's simpler, and therefore somewhat quicker and somewhat smaller (which is a win if you're statically linking your libc).
System: Debian Sid and FreeBSD 7.0. Both with GCC 4.3.
Useful resources:
comp.lang.c FAQ | C++ FQA Lite
fputs() doesn't have to parse the string "%s" to figure out that all you want to do is print a string.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
In other words, you have to prepare your string ahead of time for fputs, where fprintf allows you to format at the time of outputting.
Quzah.
Hope is the first step on the road to disappointment.
If you're just trying spit out a simple message that doesn't need formatting like "You win!" then puts()/fputs() is more efficient.
If you understand what you're doing, you're not learning anything.