Saturday, May 22, 2010

Can anyone tell me another way of expressing the \n escape sequence in C programming?

Maybe using a hexa escape sequence or octal escape sequence, is there a corresponding Ascii code for the "n" in \n :-)

Can anyone tell me another way of expressing the \n escape sequence in C programming?
\n is 10 (0xA) in ASCII so you can escape it as '\xA'





Rama:


That's not quite true. '\n' is always simply '\n', when typed manually. However, a newline is as you said is:


- '\n' simply for unix systems


- '\n\r' for Windows


- '\r' old Mac systems


That happens if one uses std::endl for C++ for example.
Reply:As odd as it sounds, in ASCII "\n" or the newline is actually considered one character, so representing the n in "\n" is not going to have the desired effect.





You could probably enter the octal or hex value for newline and have it convert using something like sprintf.





The other option is to use the carriage return and line feed ASCII characters. CR+LF == \n


No comments:

Post a Comment