Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

arr[strcspn(arr, "\r\n")] = 0; – What does "\r" mean?

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;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading