What is the newline character in C? I know that different OS have different line-ending characters, but they get translated into the C newline character. What is that character?
The /r stands for return or carriage return which owes it's history to the typewriter. A carriage return moved your carriage all the way to the right so you were typing at the start of the line. The /n stands for new line, again, from typewriter days you moved down to a new line.
\r\n is the standard line-termination for text formats on the Internet. \r\n is only used on Windows Notepad, the DOS command line, most of the Windows API, and in some (older) Windows apps. \n: UNIX systems use \n as their end of line character.
'\r' is the carriage return character.
LF (character : \n, Unicode : U+000A, ASCII : 10, hex : 0x0a): This is simply the '\n' character which we all know from our early programming days. This character is commonly known as the 'Line Feed' or 'Newline Character'.
It's \n
. When you're reading or writing text mode files, or to stdin/stdout etc, you must use \n
, and C will handle the translation for you. When you're dealing with binary files, by definition you are on your own.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With