summaryrefslogtreecommitdiffstats
path: root/4/2.c
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-12-05 12:57:53 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-12-05 12:57:53 +0800
commit3573f9e8fc065808a48322a4d40387ab8db4a5c2 (patch)
tree0d33ded8bd77b0c589e9679732408632e863a0ad /4/2.c
parent41e16a70c637264428db4b13617d88de362a8156 (diff)
downloadk&r-exercises-3573f9e8fc065808a48322a4d40387ab8db4a5c2.tar.gz
4.2
Diffstat (limited to '4/2.c')
-rw-r--r--4/2.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/4/2.c b/4/2.c
index 2f94001..3a3fa0b 100644
--- a/4/2.c
+++ b/4/2.c
@@ -49,7 +49,10 @@ double atof(char s[]) {
exp_sign = s[i] == '-' ? -1 : 1;
- for (i++, exp = 0; isdigit(s[i]); i++)
+ if (s[i] == '-' || s[i] == '+')
+ i++;
+
+ for (exp = 0; isdigit(s[i]); i++)
exp = 10 * exp + (s[i] - '0');
if (exp_sign < 0)