I need to check if my program is correctly inputting these characters in my strings, so how can I see a “raw” string with these characters not parsed but actually shown?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you read input (from file or from user) the special escape codes are not parsed. It’s only in string and character literals in the source that the compiler treats those specially.
Edit: Simple example program with input and output to show what I’m talking about.
Example run of the above program:
The function
fgetsleaves the actual newline at the end of the string. However, the sequences\nand\tin the input does not get translated to newline or tab (respectively). That is because it’s not the input or output functions that handles these special character sequences, but the compiler.If you have those sequences inside a string or character literal in the source, then the compiler recognizes those and changes them to a proper newline, tab or whatever it is you wrote. However, as the compiler doesn’t know anything about input read from a file or from a user, these sequences are not translated.
Edit 2: In case you wonder about how to show literal special characters in a string, then please see this program:
When running the program: