C char* to int conversion

Niek picture Niek · Oct 30, 2012 · Viewed 163.6k times · Source

How would I go about converting a two-digit number (type char*) to an int?

Answer

Aamir picture Aamir · Oct 30, 2012

atoi can do that for you

Example:

char string[] = "1234";
int sum = atoi( string );
printf("Sum = %d\n", sum ); // Outputs: Sum = 1234