char array to integer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • hedylogus

    char array to integer

    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.



Working...