differences between \r\n and \n

Started by
10 comments, last by helix 18 years, 4 months ago
I eventually had to learn this, I knew it! , now that I am making a font thing for my game I finally figure out that I have to learn the difference between \r\n and \n
------ XYE - A new edition of the classic Kye
Advertisement
\r\n is a carriage return followed by a newline. \n is just the newline. Since the days of teletype machines is mostly gone, \r\n is usually converted to just \n and handled that way.
Some operating systems use the value 0x0a ('\n') to mark the end of a line. Some use the value 0x0d ('\r') to mark the end of a line. Some use the sequence 0x0d,0x0a ("\r\n").

The C and C++ libraries automatically convert to the proper marker when a '\n' is written to file or stream in text mode, and convert from the end-of-line marker to '\n' when reading from a file or stream in text mode.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
For maximal compatibility you might want to use "\r\n" whenever possible. Some programs such as notepad don't interpret "\n" as "\r\n" hence don't display the text correctly.
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
Quote:Original post by Skeleton_V@T
For maximal compatibility you might want to use "\r\n" whenever possible. Some programs such as notepad don't interpret "\n" as "\r\n" hence don't display the text correctly.


That's not really true; as long as you use the correct text mode flags on file output, the OS should convert \n to the correct line terminator for the operating system.
Quote:Original post by Skeleton_V@T
For maximal compatibility you might want to use "\r\n" whenever possible. Some programs such as notepad don't interpret "\n" as "\r\n" hence don't display the text correctly.


On the other hand, some programs don't expect the '\r' before \n, and so, they end up printing something like ^M at the end of every line.
I'm not aware of such a program, anyway, I rely on the API to do the convertions, thanks for correcting this.
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
I know when I did some .NET programming last week and used the text edit box I had to use \r\n to get a new line. Just using \n resulted in garbage.
Quote:Original post by njpaul
I know when I did some .NET programming last week and used the text edit box I had to use \r\n to get a new line. Just using \n resulted in garbage.


.Net has Environment.NewLine to solve such problems
Quote:Original post by Anonymous Poster
Quote:Original post by njpaul
I know when I did some .NET programming last week and used the text edit box I had to use \r\n to get a new line. Just using \n resulted in garbage.

.Net has Environment.NewLine to solve such problems

OT: But it really _should_ be transparent in WinForms controls, too sad it isn't. Getting/setting text for a control should do the same thing as opening a file in text-mode: writing \n should be converted to \r\n and reading \r\n should be converted to \n.
Arguing on the internet is like running in the Special Olympics: Even if you win, you're still retarded.[How To Ask Questions|STL Programmer's Guide|Bjarne FAQ|C++ FAQ Lite|C++ Reference|MSDN]

This topic is closed to new replies.

Advertisement