I am using fprintf to append a string to a document, here is the line I have a question about:
fprintf(win, bff[i - 2] != '\n' && bff[i - 2] != '\r' ? "\nmultiscreen=1" : "multiscreen=1");
The code works, it appends multiscreen=1 to the next available line in the file.
But if I understand correctly wouldn’t it NOT be adding a NULL character to the end of multiscreen=1?
Does this even matter since I’m writing it to a file and the trailing NULL in a string is a C thing?
Or would it be more correct to use fputs instead of fprintf?
String literals automatically have a
0as the last character in them. So you don’t need to add one yourself.The
NULterminator is only forfprintf(or whatever string function you are using) to know when to stop writing characters from the pointer; noNULis actually ever written to the file.And yes, I would recommend using
fputsinstead offprintfsince you’re not using any of the formatting facilities offprintf, unless you use pmg’s suggestion in the comments to your question which does use formatting sequences.