how to convert numbers from char array

hello i want to convert in loop for example this

char number[]="54465465445646848640";

and in loop convert these element to int one by one.
char is really a byte (so, an 8 bit integer). So, you can simply do this:

1
2
3
4
5
char number[] = "54465465445646848640";
int size = sizeof(number) / sizeof(char) - 1; // Total chars in the array, -1 because your string has an invisible \0.
std::vector<int> result(size); // Initialize a result vector with size equal to your array's
for (int i = 0; i < size; ++i)
  result[i] = number[i];


Good luck

ps: If you want the integer values that are equal to the numbers in the string, subtract them by 48 (= the character code of '0')
Last edited on
Topic archived. No new replies allowed.