printf() and puts() 
Author Message
 printf() and puts()

Newbie question:
What exactly is the difference between printf() and puts()?  I understand that
printf() is a "formatted I/O function," but what does that really mean?  How
and why does printf() offer more "formatting control?"
Thanks in advance.
-Adam
--



Wed, 01 May 2002 03:00:00 GMT  
 printf() and puts()

in comp.lang.c.moderated:

Quote:
> Newbie question:
> What exactly is the difference between printf() and puts()?  I understand that
> printf() is a "formatted I/O function," but what does that really mean?  How
> and why does printf() offer more "formatting control?"
> Thanks in advance.
> -Adam

puts() does not offer any formatting control.  Anything up to and
excluding the terminating '\0' is dumped to the standard output, then
a newline is added.

With printf() you can do things like:

int x = 9;

printf("x is %d\n", x);

And printf() will replace the "%d" characters in the string with the
current value of the integer x.  puts() does not do any such
replacement or formatting.

Finally, printf() does not automatically add a newline to the end of
the output like puts() does, which can be handy for displaying prompts
to the user.  However if you do not end a printf() string with a '\n',
you should flush the standard output to make sure the prompt shows up
right away:

printf("Enter a number: ");
fflush(stdout);

Assuming the standard output is a text video display or terminal,
these two lines will leave the cursor in the position indicated by the
underscore:

Enter a number: _

For the user to type input.

Jack Klein
--
Home: http://jackklein.home.att.net
--



Wed, 01 May 2002 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. printf, puts, gets etc don't work when stepping into

2. I/O with puts/printf

3. what is the difference between puts and printf ?

4. Why you should use puts(3) when you don't need printf(3)

5. printf() vs. puts()

6. why use puts instead of printf?

7. VC7: cstdio doesn't put printf in std

8. replacing printf with my printf, then calling C lib's printf

9. (void)printf() vs. printf()

10. Re(2): Re(2): (void)printf() vs. printf()

11. Re(2): (void)printf() vs. printf()

12. an ATL Activex Control could not put on dialog in VC, but it can be put on VB dialog

 

 
Powered by phpBB® Forum Software