Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

What do you mean by '\o<octal number>'?

  1. Sep 9, 2009 #1
    I'm not sure what they mean here...can someone explain?

    When ever I do, for e.g -

    "\o7" or "\o42" in printf to try and print ASCII code 7 or 52 (decimal)

    Compiler returns \o is not recognized.

    However if I do "\07" or "\042" I get the characters 7 and 52 (as in ASCII code).


    My question is, what is this 'o'?
     
  2. jcsd
  3. Sep 9, 2009 #2
    You can use "\ooo" where "ooo" is 1 to 3 octal digits. In other words, "ooo" can be "1", "304", "12", "77"....but not "o12."

    You can also use "\xhh", where "hh" is 1 or 2 hexadecimal digits...ie, "\x34" or "\x9f" or "\xb."

    This is the complete ascii table:
    http://www.cs.utk.edu/~pham/ascii_table.jpg [Broken]

    Some of the characters have special escape codes defined, such as "\n" for newline, which has hex value "A" and octal value "012", therefore the following are all equivalent:

    \n
    \xa
    \xA (pretty sure this is case insensitive)
    \012
    \12 (im pretty sure the leading zero can be dropped)
     
    Last edited by a moderator: May 4, 2017
  4. Sep 10, 2009 #3

    Mark44

    Staff: Mentor

    Octal \042 is the code for the character with ASCII code 34, not 52. This character is the double-quote, ".
     
  5. Sep 22, 2009 #4
    Yes it can.

    Thanks everyone!
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook