Escape Characters

This is a discussion on Escape Characters within the C Programming forums, part of the General Programming Boards category; I want to learn about two of the escape characters. \N where N is an octal constant \xN where N ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    93

    Escape Characters

    I want to learn about two of the escape characters.

    \N where N is an octal constant
    \xN where N is an hexadecimal constant

    Where and how can I use it. I couldn't use it in printf.

    Can you show me an example?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,175
    Quote Originally Posted by GokhanK View Post
    I want to learn about two of the escape characters.

    \N where N is an octal constant
    \xN where N is an hexadecimal constant

    Where and how can I use it. I couldn't use it in printf.

    Can you show me an example?
    Why couldn't you use it in printf? Try this: printf("\x41\n");

    It should print an 'A', which has hex value 0x41 in the ASCII table.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    If you cannot type a character, but you know its number, that's when you can use it. For example, a specific number in an encoding might refer to a Japanese kanji, or an umlaut a in German, or a Cyrillic letter. One place they would be used is in string tables (but not std::string) for an application that needs to know how to display things in various languages.

  4. #4
    Registered User
    Join Date
    Dec 2010
    Posts
    93
    Quote Originally Posted by itsme86 View Post
    Why couldn't you use it in printf? Try this: printf("\x41\n");

    It should print an 'A', which has hex value 0x41 in the ASCII table.
    I hadn't been able to use it because I had totally misunderstood the structure and logic. Thanks a lot for your nice reply. I have understood it now.

    Quote Originally Posted by whiteflags View Post
    If you cannot type a character, but you know its number, that's when you can use it. For example, a specific number in an encoding might refer to a Japanese kanji, or an umlaut a in German, or a Cyrillic letter. One place they would be used is in string tables (but not std::string) for an application that needs to know how to display things in various languages.
    And this one explains me a lot about where I will use it. Thanks to you also.

  5. #5
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    Use the '\o' escape sequence like you use the '\x' one to print octal values as characters.
    Quote Originally Posted by The Jargon File
    Microsoft Windows - A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition.

  6. #6
    Registered User
    Join Date
    Dec 2010
    Posts
    93
    Quote Originally Posted by Babkockdood View Post
    Use the '\o' escape sequence like you use the '\x' one to print octal values as characters.
    I tried that one but it doesn't work

    For example; to print A

    printf("\x041"); or printf("\101");

    Both of them work But \o101 doesn't work.

  7. #7
    Third Eye Babkockdood's Avatar
    Join Date
    Apr 2010
    Posts
    352
    Quote Originally Posted by GokhanK View Post
    I tried that one but it doesn't work

    For example; to print A

    printf("\x041"); or printf("\101");

    Both of them work But \o101 doesn't work.
    Oh.

    I stand corrected, then.
    Quote Originally Posted by The Jargon File
    Microsoft Windows - A thirty-two bit extension and graphical shell to a sixteen-bit patch to an eight-bit operating system originally coded for a four-bit microprocessor which was written by a two-bit company that can't stand one bit of competition.

  8. #8
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    You might have seen, something like \033 which is an octal character constant - exactly \###.
    Last edited by whiteflags; 02-24-2011 at 08:03 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A development process
    By Noir in forum C Programming
    Replies: 37
    Last Post: 07-10-2011, 11:39 PM
  2. Replies: 2
    Last Post: 09-16-2009, 07:00 AM
  3. Replies: 10
    Last Post: 07-10-2008, 04:45 PM
  4. stringstream with escape characters
    By Queue in forum C++ Programming
    Replies: 1
    Last Post: 11-22-2006, 06:24 PM
  5. Escape characters
    By The Gweech in forum C++ Programming
    Replies: 3
    Last Post: 07-09-2002, 06:38 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21