4 ms·
Printf is perfectly acceptable when a string is being printed without format-specifiers. You are abstracting your limited experience to be true for all situati
by IncRnd 6y ago
Printf is perfectly acceptable when a string is being printed without format-specifiers. You are abstracting your limited experience to be true for all situations.
For a simple example, how will puts print a string without a line termination?
- orwin 6y agoHence, use write()! Not completely joking here, I think everytime I've had to use strings to make two C programs communicate over a network, write() was as easy to use as printf(). Obviously it's not true when communicating with a user.
- saagarjha 6y agowrite requires a length, it’s not specifically designed for working with strings like printf is.
- IncRnd 6y agoThat's not a bad point for many cases. I was pointing out that the coding rule in the upper comment to always use puts, and never printf, is bad advice. I am glad to hear you mention network coding. More people should do that, so fewer people make statements like, "always use puts for writing strings, never printf."
- MaxBarraclough 6y ago> You are abstracting your limited experience to be true for all situations. You aren't qualified to comment on my experience. > For a simple example, how will puts print a string without a line termination? Use fputs. If we're still just writing a simple string, there's no need to reach for a function with format-specifier interpretation.
- IncRnd 6y ago> You aren't qualified to comment on my experience. I think the language barrier made you believe I was personally attacking you. You literally constructed a general argument from a specific statement. That is a logical fallacy called fallacy of composition. If you find yourself printing a string with printf and getting a different result from fputs, it has nothing to do with a newline but with not having checked the string's contents. Ignoring that doesn't fix code with unvalidated input.