Converting an octal code to Char

This is a discussion on Converting an octal code to Char within the C Programming forums, part of the General Programming Boards category; Is there anyway that i can read an octal code then covert it to character ?? like if i key ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    41

    Converting an octal code to Char

    Is there anyway that i can read an octal code then covert it to character ??

    like if i key in '\012' it will read as '\n' ???
    if i key in '141' it will read as 'a' ???

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,751
    Lots of ways

    If you use the %i mode in say scanf(), then any integers you type in with a leading 0 are octal

    012
    0141
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    41
    I couldnt use scanf as the parameter is being pass in as a string.
    coz when i read the argument it is in string format. what the function does is it read the \012 and store it in argv[1] and then pass it to convertOctal function so that it is able to convert the numbers to a character and then only store it in a variable.



    Code:
    main(int argc,  char *argv[])
    {
    
          convertOctal(argv[1]);
    }

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,751
    So use sscanf() then
    Or strtol() with the base set to 8
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ text file
    By statquos in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2008, 02:42 PM
  2. Replies: 7
    Last Post: 06-16-2006, 10:23 PM
  3. Obtaining source & destination IP,details of ICMP Header & each of field of it ???
    By cromologic in forum Networking/Device Communication
    Replies: 1
    Last Post: 04-29-2006, 03:49 PM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 12:58 PM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM

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