Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the newline character in the C language: \r or \n?

Tags:

c

newline

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?

like image 597
andy Avatar asked Aug 22 '13 12:08

andy


People also ask

Is \r the same as \n?

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.

What is \r and n?

\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.

What does \r mean in C?

'\r' is the carriage return character.

What is the use of a '\ n 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'.


1 Answers

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.

like image 151
Crowman Avatar answered Sep 26 '22 11:09

Crowman