Output of a program that doesn't print a newline at last

  • Thread starter Johannes Schaub (litb)
  • Start date
J

Johannes Schaub (litb)

Some guy in a forum said: "C language itself makes no guarantees about the
output of a program if the output does not end in a newline character.". See
http://stackoverflow.com/questions/2141745/what-to-replace-in-this-c-
puzzle/2141969#2141969 . Is the guy right? What paragraphs of the Standard
are of interest?

Thanks!

(this was also sent to comp.std.c, since i think it's also a practical
question so it belongs to .lang.c too).
 
P

Peter Nilsson

Johannes Schaub (litb) said:
Some guy in a forum said: "C language itself makes no
guarantees about the output of a program if the output
does not end in a newline character.".
See <http://stackoverflow.com/questions/2141745/what-to-replace-in-this-c-puzzle/2141969#2141969> .
Is the guy right?
Yes.

What paragraphs of the Standard are of interest?

7.19.2p2 "A text stream is an ordered sequence of characters
composed into lines, each line consisting of zero or more
characters plus a terminating new-line character. Whether
the last line requires a terminating new-line character is
implementation-defined. ..."

If you've ever failed to terminate the last line sent to
an old line printer you'll know one potential impact.
 
P

Phred Phungus

Peter said:
7.19.2p2 "A text stream is an ordered sequence of characters
composed into lines, each line consisting of zero or more
characters plus a terminating new-line character. Whether
the last line requires a terminating new-line character is
implementation-defined. ..."

If you've ever failed to terminate the last line sent to
an old line printer you'll know one potential impact.

I guess it isn't an error, but I've made the mistake of omitting the
newline dozens of times. For me, it's like Dick Van Dyke tripping over
the ottoman. I think I'm doing so well to get the specifier right and
and have a syntactical statement that I space it out.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top