H
happy
I want to implement atoi function which converts string to an integer.
So I did this :
int atoi(char str[])
{
int i, num;
for( num = 0, i = 0 ; isdigit(str) ; i++)
num = num * 10 + str - '0' ;
return num;
}
Here I wnat to know is there any way to tell user if num goes out of
range of int ?
I mean we can't check num after overflow as it will be UB so is there
a way to check if str[] contains large integer ?
So I did this :
int atoi(char str[])
{
int i, num;
for( num = 0, i = 0 ; isdigit(str) ; i++)
num = num * 10 + str - '0' ;
return num;
}
Here I wnat to know is there any way to tell user if num goes out of
range of int ?
I mean we can't check num after overflow as it will be UB so is there
a way to check if str[] contains large integer ?