What is the difference between printf() and puts() in C?

alex picture alex · Mar 16, 2010 · Viewed 189.4k times · Source

I know you can print with printf() and puts(). I can also see that printf() allows you to interpolate variables and do formatting.

Is puts() merely a primitive version of printf(). Should it be used for every possible printf() without string interpolation?

Answer

Michael Kristofik picture Michael Kristofik · Mar 16, 2010

puts is simpler than printf but be aware that the former automatically appends a newline. If that's not what you want, you can fputs your string to stdout or use printf.