CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums
Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2006

    Setting char value

    All, I have attached a snapshot of the issues I am dealing with.

    const char CR = '\13';
    const char LF = '\10';

    const char CR2 = '\15';
    const char LF2 = '\12';

    In the locals watch window it shows that the CR value is 11 instead of 13, and my line-feed LF has a value of 8 instead of 10. If I add 2 to the value as CR2 and LF2 show, then the watch windows shows them as 13 and 10.

    What am I doing wrong.
    C++ Express 2010

    Attached Images Attached Images  

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003

    Re: Setting char value

    If you want it to be 13 just set it to 13.

    CR = 13;
    or you could say CR = '\r';
    LF = '\n";

    You're setting octal values and your debugger is showing them as decimal.

  3. #3
    Join Date
    Dec 2006

    Re: Setting char value

    Easy fix.
    Thanks for the response.


  4. #4
    Join Date
    Apr 2000
    Belgium (Europe)

    Re: Setting char value

    This is because:
    '\10' = 10 in octal = 8 in decimal

    there is also a notation for hexadecimal:
    'x10' = 10 in hexadecimal = 16 in decimal

    There is... strangely enough... no way in C/C++ to enter a decimal value as an escape sequence, for some special characters there are specific sequences though. Such as
    '\n' for linefeed/newline (10 decimal, '\xa' or '\12')
    '\r' for carriage return (13 decimal '\xd' or '\15')

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width