What atoi() function does?
atoi() function is used to convert a string to an integer
#include
int own_atoi(const char *str)
{
int value = 0;
if(str)
{
while(*str && (*str != ‘0’))
{
value = (value * 10) + (*str – ‘0’);
str++;
}
}
return value;
}
int main()
{
int value;
value = own_atoi(“2345678”);
printf(“value = %d\n”, value);
return 0;
}
Output:
$ ./a.exe
value = 2345678