Cite here: )
It goes back to mechanical teletypes; if you issued a line feed followed by carriage return you got a few characters printed backwards in a diagonal stripe because there was insufficient time for the carriage to move back to the left before it started printing. To overcome this, the carriage return is issued first to give the carriage enough time to return, whilst line feeding, before printing started. It has stuck as a standard ever since.
and here:
Different Operating Systems handle newlines in a different way. Here is a short list of the most common ones:When string are read from user input, escape character can't be explicitly input. For example, in case which string are read from the command line argument, when the user give argument "hello\nworld", the string read in and stored will be "hello\\nworld". This is because escape characters usually are parsed as format presentation rather than literal occurrence (actually, this is the "unescapted" meaning). For the same reason, in the programming codes escape characters, the literal form of format presentation, are used instead of draw a format presentation that the compiler could understand, which is obviously of non-sense.
- DOS and Windows
They expect a newline to be the combination of two characters, namely '\r\n' (or 13 followed by 10).
- Unix (and hence Linux as well)
Unix uses a single '\n' to indicate a new line.
- Mac
Macs use a single '\r'.
Note that using escape characters to specify the format presentation is not the definition of escape character, though in many cases they're used in this way.

No comments:
Post a Comment