4 ms·
Even better would of course be puts(string); -- no point in running a parser that will scan each character looking for formatting instructions, when you don't h
by unwind 9y ago
Even better would of course be puts(string); -- no point in running a parser that will scan each character looking for formatting instructions, when you don't have any.
Using puts() will give you a terminating line feed though, which might not be what you want for a prompt. On the other hand that likely saves you from having to deal with output-flushing and so on ... Might be nice for teaching.
- red_admiral 9y agofputs(stdout, string) avoids the newline too, although you'd now have to teach two functions (printf, fputs) as well as saying what "stdout" means. In a teaching context, printf("%s", string) is probably best as printf is being used in other lines in the same file already.
- boomlinde 9y agoWhat sacrifices you are willing to make in a teaching context is a matter of taste. You draw the line somewhere between using printf in an entirely acceptable way where fputs would have been better suited, and using printf in another entirely acceptable way where fputs would have been better suited. That seems inconsistent and hard to justify.