I heard that you should avoid leading newlines when using
printf. So that instead of
printf("\nHello World!") you should use
In this particular example above it does not make sense, since the output would be different, but consider this:
printf("Initializing"); init(); printf("\nProcessing"); process_data(); printf("\nExiting");
printf("Initializing\n"); init(); printf("Processing\n"); process_data(); printf("Exiting");
I cannot see any benefit with trailing newlines, except that it looks better. Is there any other reason?
I'll address the close votes here and now. I don't think this belong to Stack overflow, because this question is mainly about design. I would also say that although it may be opinions to this matter, Kilian Foth's answer and cmaster's answer proves that there are indeed very objective benefits with one approach.
process_data()print anything themselves? What would you expect the result to look like if they did?
\nis a line terminator, not a line separator. This is evidenced by the fact that text files, on UNIX, almost always end in