All reference for converting a string to integer point to use “atoi()” function.. how-ever please note that, it does not act like what you read above.. That said, if your string contains digits it will convert to integer ,BUT the string has to start with “digit”..
#include <stdio.h>
#include <stdlib.h>
int main()
{
//char str[]="a123";
char str[]="12a123";
printf ("%d", atoi(str));
return 0;
}
You get "12" as an output here . How-ever if you enable the commented part (ie:char str[]="a123";) ,you will get "0" and not "12".
atoi() is useful when taking integer arguments from the user.
For additional reference, refer man page