Using atoi with char

John Doe picture John Doe · May 26, 2010 · Viewed 51.2k times · Source

Is there a way of converting a char into a string in C?

I'm trying to do so like this:

   char *array;

   array[0] = '1';

   int x = atoi(array);

   printf("%d",x);

Answer

BlueRaja - Danny Pflughoeft picture BlueRaja - Danny Pflughoeft · May 26, 2010
char c = '1';
int x = c - '0';
printf("%d",x);