From 886eadeaa6980ec90dab2f3be21ecd175e5064bd Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Sat, 18 Dec 2021 14:44:17 +0800 Subject: 4.10 --- 4/10.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to '4/10.c') 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; } -- cgit v1.2.3