The C standard provides two functions, puts
and fputs
, with puts(s)
behaving as fputs(s, stdout)
except that it additionally appends a newline:
The
puts()
function shall write the string pointed to bys
, followed by a<newline>
, to the standard output streamstdout
.
What is the rationale for this difference in behavior between puts
and fputs
?
The puts
function specifically writes to stdout
which is commonly a console. Because console output is typically line bufered, it's convenient to not have to explicitly add a newline to a string to print.
The fputs
function can write to any given FILE
object, not just stdout
, so by not automatically adding a newline it makes the function more flexible in the general case.