mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-25 06:49:36 +03:00
Merge pull request #807 from BillKek/master
fix: assertion failed on negative numbers in `conversions/c_atoi_str_to_integer.c`
This commit is contained in:
commit
121c7132a0
@ -30,9 +30,15 @@ int c_atoi(const char *str)
|
|||||||
|
|
||||||
/* store the sign if it is negative sign */
|
/* store the sign if it is negative sign */
|
||||||
if (str[i] == '-')
|
if (str[i] == '-')
|
||||||
|
{
|
||||||
sign = -1;
|
sign = -1;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
else if (str[i] == '+')
|
else if (str[i] == '+')
|
||||||
|
{
|
||||||
sign = 1;
|
sign = 1;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
/* converting char by char to a numeric value */
|
/* converting char by char to a numeric value */
|
||||||
while (str[i] >= 48 && str[i] <= 57 && str[i] != '\0')
|
while (str[i] >= 48 && str[i] <= 57 && str[i] != '\0')
|
||||||
|
Loading…
Reference in New Issue
Block a user