Re: All programs are undefined



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"
.



Relevant Pages

  • Re: trailing blank line in a text file
    ... You do not have a trailing blank line 4, ... Your editor does not insert a trailing blank line. ... The newline is the last character of the ... therefore the last character displayed. ...
    (Fedora)
  • Re: Sig delimiter
    ... > The sig delimiter is dash dash space. ... > the OE editor to not strip the sig delimiter's trailing spaces. ... > that something a changing of the OE editor to cease to strip trailing ...
    (news.software.readers)
  • Re: [OT] Fuck the police (again)
    ... Problem was any moron could see within 2 seconds that they were fakes. ... just hated him on TV) he has balls as an editor. ... Allow me to demonstrate as I simulate the "urine" stream from A. Notice the ... similarity in droplet size and stream flow. ...
    (uk.comp.sys.mac)
  • Re: Free Ruby eBook
    ... terminating in a newline). ... I can't think of many editors for Windows which care at ... that removes a terminating newline silently? ... Any text editor that takes ...
    (comp.programming)
  • Re: Finding & replacing (KATE, Word, OpenOffice)
    ... >> i.e. newline stuffing rather than depletion. ... > while editing the same text in a text editor - KATE. ... in order to accomplish the ... > Happy holidays to you too... ...
    (comp.windows.x.kde)