diff options
| author | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-12-05 13:04:07 +0800 |
|---|---|---|
| committer | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-12-05 13:04:07 +0800 |
| commit | 340b06848ed702945d50ec32a31087bfb9cd4ef7 (patch) | |
| tree | 4e745d6fdf9e01b916309015eb0007f81deb4138 /4/2.c | |
| parent | 51f836e4a41b05574e0da9a45612ee70bf9fcaba (diff) | |
| download | k&r-exercises-340b06848ed702945d50ec32a31087bfb9cd4ef7.tar.gz | |
4.2
Diffstat (limited to '4/2.c')
| -rw-r--r-- | 4/2.c | 3 |
1 files changed, 2 insertions, 1 deletions
@@ -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; |
