Code: Select all
#include <stdio.h>
void main(void)
{
char myString[] = "00008";
int number;
number = atoi(myString);
printf("Hello World! %i\n", number);
}
I did. It has a leading zero so is octal and an eight isn't a valid octal digit.
atoi() is only the right answer if the string is guaranteed to hold a valid non-zero number.
More interestingly you can set it to bases other than 10
Code: Select all
The behavior is the same as
strtol(nptr, NULL, 10);
except that atoi() does not detect errors.