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. Advertising

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. lovecreatesbeauty
    Replies:
    1
    Views:
    1,154
    Ian Collins
    May 9, 2006
  2. Replies:
    3
    Views:
    761
  3. davidb
    Replies:
    0
    Views:
    809
    davidb
    Sep 1, 2006
  4. davidb
    Replies:
    6
    Views:
    1,598
    Default User
    Sep 1, 2006
  5. Replies:
    5
    Views:
    247
    Tassilo v. Parseval
    Nov 22, 2005
Loading...

Share This Page