Copying string into char array

atoi is for converting a string to integer. However, you want to convert a single character.

You can write:

number = token2[i] - '0';

This works because the digits '0' through '9' have consecutive character codes. There is no need to malloc or whatever.

Leave a Comment