diff options
| author | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-12-18 14:44:17 +0800 |
|---|---|---|
| committer | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-12-18 14:44:17 +0800 |
| commit | 886eadeaa6980ec90dab2f3be21ecd175e5064bd (patch) | |
| tree | 5527363063e3c9c5381e0c1d3d7f6f247992da3d /4 | |
| parent | 67a788f38119f21b935d57c094314d8ef0d24e5d (diff) | |
| download | k&r-exercises-886eadeaa6980ec90dab2f3be21ecd175e5064bd.tar.gz | |
4.10
Diffstat (limited to '4')
| -rw-r--r-- | 4/10.c | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -119,12 +119,11 @@ int line[MAXLINE]; int mgetline() { int i, c; - for (i = 0; i < MAXLINE - 1 && (c = getchar()) != EOF; i++) { + for (i = 0; i < MAXLINE - 1 && (c = getchar()) != '\n' && c != EOF; i++) { line[i] = c; - if (c == '\n') - break; } + line[i++] = '\n'; line[i] = 0; idx = 0; return c == EOF ? 0 : 1; @@ -149,6 +148,7 @@ int getop(char s[]) { while (isdigit((s[++i] = c = line[idx++])) || (c == '.' && isdigit(line[idx + 1]))) ; + idx--; rc = NUM; } else if (isalpha(c) && line[idx + 1] == ' ' && line[idx + 2] == '=') { idx += 2; @@ -156,6 +156,8 @@ int getop(char s[]) { } else { while (isalnum(s[++i] = c = line[idx++])) ; + s[i] = 0; + idx--; rc = strcmp("LOUT", s) == 0 ? VAR : FUN; } |
