Advertisement
paulogp

char2int

Aug 5th, 2011
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. // apple xcode
  2. // paulogp
  3.  
  4. /* char2int */
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. int main (int argc, const char * argv[])
  9. {
  10.     char the_char_vector[3] = {'2', '3', '4'};
  11.     int the_num, i;
  12.     long the_merge_num;
  13.    
  14.     // char 2 int
  15.     for (i = 0; i < 3; i++)
  16.     {
  17.         the_num = the_char_vector[i] - '0';
  18.         printf("%i: %i\n", (i + 1), the_num);
  19.     }
  20.    
  21.     // get all as one number
  22.     the_merge_num = strtol(the_char_vector, NULL, 0);
  23.     printf("tudo: %li\n", the_merge_num);
  24.    
  25.     return (0);
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement