summaryrefslogtreecommitdiffstats
path: root/4
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-12-18 14:44:17 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-12-18 14:44:17 +0800
commit886eadeaa6980ec90dab2f3be21ecd175e5064bd (patch)
tree5527363063e3c9c5381e0c1d3d7f6f247992da3d /4
parent67a788f38119f21b935d57c094314d8ef0d24e5d (diff)
downloadk&r-exercises-886eadeaa6980ec90dab2f3be21ecd175e5064bd.tar.gz
4.10
Diffstat (limited to '4')
-rw-r--r--4/10.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/4/10.c b/4/10.c
index ef7493f..88b6755 100644
--- a/4/10.c
+++ b/4/10.c
@@ -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;
}