I have a question. I am learning C programming and while reading and storing user input into a char array I came across this code. Can someone explain to me what the "\r"
mean?
Thank you
arr[strcspn(arr, "\r\n")] = 0;
CodePudding user response:
\r
is ASCII character 13, called "CR" or "carriage return".
Unix traditionally used \n (ASCII character 10, LF, line feed) as the end of a line, but Windows traditionally uses \r followed by \n (note that a lot of Windows functions do convert it to just \n). So to detect both, you can check for both \r and \n.
CodePudding user response:
As user253751 suggested it is the carriage return.
To give some more context, there are the most important escaped character sequences related to new line, spaces etc..
Character | Effect |
---|---|
\n | newline |
\r | carriage return |
\t | horizontal tab |
\v | vertical tab |
Hope it is helpful!