Re: All programs are undefined
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Fri, 18 Jan 2008 19:34:12 -0800
Joe Wright <joewwright@xxxxxxxxxxx> writes:
Keith Thompson wrote:[...]
I've posted a question to comp.std.c, subject "Last line with or
without new-line".
Whose business is it? I suggest it is not C which defines 'line' but
perhaps the OS and its utilities.
Sorry, but the C standard does define "line"; see C99 7.19.2p2.
I run the following program..
#include <stdio.h>
int main(void) {
printf("Hello world\n");
printf("Good bye");
return 0;
}
..and redirect its output to a file, nl.txt. Now using a hex editor I
see that the second line is, in fact, not terminated with a
newline.
You probably ran it under an implementation that *doesn't* require a
new-line on the last line of a text stream. The results are exactly
what I'd expect.
Now I open nl.txt in an editor (edit.com?). I modify the file
changing the 'H' to 'J' and save it. Now as I look at it in the hex
editor I find the editor has added the newline to the last line of the
file.
I seem to remember vi will do the same thing.
The authors of those programs (which may or may not be implemented in
C) chose to transform a text file without a trailing new-line into one
with a trailing new-line. And how is this relevant to text streams in
C?
--
Keith Thompson (The_Other_Keith) <kst-u@xxxxxxx>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- References:
- Why this works???
- From: Kenny McCormack
- Re: Why this works???
- From: Tomás Ó hÉilidhe
- Re: Why this works???
- From: Kenneth Brody
- All programs are undefined, Re: Why this works???
- From: pete
- Re: All programs are undefined, Re: Why this works???
- From: Kaz Kylheku
- Re: All programs are undefined, Re: Why this works???
- From: pete
- Re: All programs are undefined, Re: Why this works???
- From: pete
- Re: All programs are undefined, Re: Why this works???
- From: Keith Thompson
- Re: All programs are undefined, Re: Why this works???
- From: pete
- Re: All programs are undefined, Re: Why this works???
- From: Kaz Kylheku
- Re: All programs are undefined
- From: pete
- Re: All programs are undefined
- From: Keith Thompson
- Re: All programs are undefined
- From: Harald van Dijk
- Re: All programs are undefined
- From: pete
- Re: All programs are undefined
- From: Keith Thompson
- Re: All programs are undefined
- From: Joe Wright
- Why this works???
- Prev by Date: Re: Standard integer types vs <stdint.h> types
- Next by Date: Re: Standard integer types vs <stdint.h> types
- Previous by thread: Re: All programs are undefined
- Next by thread: Re: All programs are undefined, Re: Why this works???
- Index(es):
Relevant Pages
|