Jump to content
  • Advertisement
Sign in to follow this  
mrmrcoleman

Carriage return character?

This topic is 4837 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am reading a serial stream from a device and I don't recognise the character that is being used as an end of line/carriage return. It looks like a stick man with no legs... i.e. o -|- But with all the parts touching if you will. Does anybody know what this character is or what it's associated ASCII code is? Thanks, Mark.

Share this post


Link to post
Share on other sites
Advertisement
There's different newlines for different platforms (and thus probably devices expecting to be on those platforms).

IIRC, the common ones are:

Windows: \r\n
*nix/OSX: \n
Old Mac: \r

(these are all C++ style escapes)

Quote:
Original post by mrmrcoleman
Hmm, I just stepped through it in debug and apparently it is a 12.

WTF?


http://www.robelle.com/library/smugbook/ascii.html

				Control
Char Oct Dec Hex Key Control Action

FF 14 12 c ^L Form Feed, page eject

Share this post


Link to post
Share on other sites
Assuming you opened the stream in text mode, you should recognize the end of line as '\n'. In input controls it should be encoded as '\r\n'.
Yes char 'n' = 12 = 0x0C

Share this post


Link to post
Share on other sites
What matters is not what the character looks like but what its numerical value is. Depending on the application you are using to view the text/data newlines could be represented as anything. Since a newline is a control character, and not a printable character, the application may just have chosen a fancy glyph to represent newlines to better let you know when they are present. So, the numerical value of a newline is 10 (in decimal) or 0x0A in Hex. A carriage return is 13 in decimal and 0x0D in hex. Like said in a previous post, different platforms have different combination of newlines and carriage returns to represent newlines.

Hope that helps

Share this post


Link to post
Share on other sites
Forgot to say, It's always a good idea to specify the character set as well, which in this case is ASCII.

Share this post


Link to post
Share on other sites
Quote:
Original post by blizzard999
Yes char 'n' = 12 = 0x0C


Wrong.

'\n' == 10 == 0x0A == "Line Feed"
'\r' == 13 == 0x0D == "Carriage Return"
'n' == 110 == 0x6E == "Latin lowercase letter N"
'\f' == 12 == 0x0C == "Form Feed, page eject"

This is not a normally used character. Serial devices have a tendancy to throw all sorts of weird characters at you, however.

Share this post


Link to post
Share on other sites
Quote:
Original post by MaulingMonkey
Quote:
Original post by blizzard999
Yes char 'n' = 12 = 0x0C


Wrong.

'\n' == 10 == 0x0A == "Line Feed"
'\r' == 13 == 0x0D == "Carriage Return"
'n' == 110 == 0x6E == "Latin lowercase letter N"
'\f' == 12 == 0x0C == "Form Feed, page eject"

This is not a normally used character. Serial devices have a tendancy to throw all sorts of weird characters at you, however.


MISTAKE! Not checked! My memory is gone...however as I (can) remember I've never specified the char value when reading from file. I simply write 'n' or use my own functions to not have to deal with these stuff.
Obviosly when I wrote 'n' I mean that the end of line in an ASCII file is '\n' that is 0x0A and not 0x0C.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!