Skip to content

Commit

Permalink
Merge pull request TheAlgorithms#807 from BillKek/master
Browse files Browse the repository at this point in the history
fix: assertion failed on negative numbers in `conversions/c_atoi_str_to_integer.c`
  • Loading branch information
ayaankhan98 authored Feb 28, 2021
2 parents 28fc15c + 6f50dd4 commit 121c713
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions conversions/c_atoi_str_to_integer.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,15 @@ int c_atoi(const char *str)

/* store the sign if it is negative sign */
if (str[i] == '-')
{
sign = -1;
i++;
}
else if (str[i] == '+')
{
sign = 1;
i++;
}

/* converting char by char to a numeric value */
while (str[i] >= 48 && str[i] <= 57 && str[i] != '\0')
Expand Down

0 comments on commit 121c713

Please sign in to comment.