summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-12-05 13:04:07 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-12-05 13:04:07 +0800
commit340b06848ed702945d50ec32a31087bfb9cd4ef7 (patch)
tree4e745d6fdf9e01b916309015eb0007f81deb4138
parent51f836e4a41b05574e0da9a45612ee70bf9fcaba (diff)
downloadk&r-exercises-340b06848ed702945d50ec32a31087bfb9cd4ef7.tar.gz
4.2
-rw-r--r--4/2.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/4/2.c b/4/2.c
index 4213054..5dcccba 100644
--- a/4/2.c
+++ b/4/2.c
@@ -11,7 +11,6 @@ int main(int argc, char *argv[]) {
char s[MAXLEN];
printf("input: ");
-
for (i = 0; i < MAXLEN - 1 && (c = getchar()) != '\n' && c != EOF; i++)
s[i] = c;
s[i] = 0;
@@ -46,10 +45,12 @@ double atof(char s[]) {
exp_sign = s[i] == '-' ? -1 : 1;
if (s[i] == '-' || s[i] == '+')
i++;
+
for (exp = 0; isdigit(s[i]); i++)
exp = 10 * exp + (s[i] - '0');
if (exp_sign < 0)
exp = exp_sign * exp;
+
if (exp < 0) {
for (j = exp; j < 0; j++)
power *= 10.0;