char array to integer

Discussion in 'C++' started by hedylogus, Aug 25, 2003.

  1. hedylogus

    hedylogus Guest

    I need to convert a char array to its corresponding unsigned integer value.
    For example, if

    char[0]=x (equivalent to 120)
    char[1]=y (=121)
    char[2]=z (=122)

    then my integer value would be 120121122. My array is 32 char long...is
    there a better way to do that than this:

    char c_array[32], i_array[96];
    i=sprintf ( i_array, "%u%u%u....%u", c_array[0],
    c_array[1],...,c_array[31] );
    my_int = atoi (i_array);

    (i made i_array 96 since each char can be represented by a 3 digit number)

    thanks.
     
    hedylogus, Aug 25, 2003
    #1
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. wwj
    Replies:
    7
    Views:
    841
  2. wwj
    Replies:
    24
    Views:
    2,991
    Mike Wahler
    Nov 7, 2003
  3. Ben Pfaff
    Replies:
    5
    Views:
    732
    Tristan Miller
    Jan 17, 2004
  4. lovecreatesbeauty
    Replies:
    1
    Views:
    1,442
    Ian Collins
    May 9, 2006
  5. Replies:
    3
    Views:
    994
  6. davidb
    Replies:
    0
    Views:
    1,031
    davidb
    Sep 1, 2006
  7. davidb
    Replies:
    6
    Views:
    1,844
    Default User
    Sep 1, 2006
  8. Replies:
    5
    Views:
    472
    Tassilo v. Parseval
    Nov 22, 2005
Loading...