To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.cadOpen lugnet.cad in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 CAD / 14516
14515  |  14517
Subject: 
Re: how does a line end?
Newsgroups: 
lugnet.cad
Date: 
Sat, 7 Apr 2007 12:37:27 GMT
Viewed: 
1661 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 wouldn’t 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 don’t know the output of the other alternatives. n gives the sequence “13\10”, or “0x0C 0x0A” in hexadecimals from Borland TC++ v3.0.
  1. - - - -
There was a Swedish finiance minister that said it’s 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 Mac’s special LF but write strictly CR+LF.

/Tore



Message has 3 Replies:
  Re: how does a line end?
 
(...) (For some unknown reason, all my backslashes disappeared in previous message.) /Tore (17 years ago, 7-Apr-07, to lugnet.cad)
  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 (...) (17 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. (...) (17 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 (...) (17 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
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR