Subject:
|
Re: how does a line end?
|
Newsgroups:
|
lugnet.cad
|
Date:
|
Sat, 7 Apr 2007 12:37:27 GMT
|
Viewed:
|
1742 times
|
| |
| |
In lugnet.cad, Chris Phillips wrote:
|
It is very easy for a programmer (regardless of the OS they are using) to
create programs that do not use proper line breaks. If you doubt it,
answer this quiz without using any reference materials:
1. Which of the following is "correct"?
a. printf("Hello, world!\r");
b. printf("Hello, world!\n");
c. printf("Hello, world!\r\n");
d. printf("Hello, world!\n\r");
2. In each of the above cases, what byte sequence will appear in the output stream?
|
1. I always use alt. b. printf(Hello, world!n); But as a self-made hobby
programmer not knowing all the tweeks and geeks, I wouldnt be surprised if the
interpretation of this may vary from one IDE to another, or if there is an .ini
file or global veraible somewhere that sets the output of n.
2. As I always use n, I dont know the output of the other alternatives. n
gives the sequence 13\10, or 0x0C 0x0A in hexadecimals from Borland TC++
v3.0.
- - - - -
There was a Swedish finiance minister that said its safer to have both a belt
and suspenders. I think the optimal fool-proof way to go is to make software as
liberal as possible when it comes to input, but conservative on output. Make it
able to read Macs special LF but write strictly CR+LF.
/Tore
|
|
Message has 3 Replies: | | Re: how does a line end?
|
| (...) Slight correction - "0x0D 0x0A" And this is kind of my point. The string you pass to printf() has \n only, which is only one byte. Offhand I don't remember if this is because of the Borland libraries, the operating system, or the fact that (...) (18 years ago, 7-Apr-07, to lugnet.cad, FTX)
| | | Re: how does a line end?
|
| Tore Eriksson schrieb: (...) After read all this and also after I have had a look at (URL) I think that Tore is right by saying "read all and save secure". Do avoid for future discussions this should be mentioned also in the LDraw Specification. (...) (18 years ago, 7-Apr-07, to lugnet.cad)
|
Message is in Reply To:
| | Re: how does a line ends?
|
| (...) I've been writing text parsing programs for over 20 years, and have found that the approach I've suggested works very well at detecting line ends in a consistent manner. Counting lines in a file by this method agrees with every compiler and (...) (18 years ago, 7-Apr-07, to lugnet.cad, FTX)
|
24 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|