Search code examples
cnewline

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


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?


Solution

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