summaryrefslogtreecommitdiffstats
path: root/4
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-12-21 18:40:24 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-12-21 18:40:24 +0800
commitfa3299b4d7e305cbd5f29e12c69227182fc2f924 (patch)
tree2a363365b6a6fef0a07ceb8d86191eaf32c1331d /4
parent81b3b08c46f906e1969334975636f8cdb4dad464 (diff)
downloadk&r-exercises-fa3299b4d7e305cbd5f29e12c69227182fc2f924.tar.gz
4.11
Diffstat (limited to '4')
-rw-r--r--4/11.c15
1 files changed, 10 insertions, 5 deletions
diff --git a/4/11.c b/4/11.c
index bb2d1f1..160ff66 100644
--- a/4/11.c
+++ b/4/11.c
@@ -14,7 +14,7 @@
#define INDEX(x) (x <= 'Z' ? x - 'A' : x - 71) /* index of the variable */
-char var[52];
+double var[52];
double lout = 0.0;
void clear();
@@ -148,15 +148,20 @@ int getop(char s[]) {
;
pc = c;
rc = i == 1 && s[0] == '-' ? '-' : NUM;
- } else if (isalpha(c) && getch() == '=') {
- s[++i] = c;
- rc = '=';
} else {
while (isalnum(s[++i] = c = getch()))
;
s[i] = 0;
pc = c;
- rc = strcmp("LOUT", s) == 0 || strlen(s) == 1 ? VAR : FUN;
+ if (c == ' ') {
+ if ((c = getch()) == '=')
+ rc = '=';
+ else {
+ pc = c;
+ rc = strcmp("LOUT", s) == 0 || strlen(s) == 1 ? VAR : FUN;
+ }
+ } else
+ rc = strcmp("LOUT", s) == 0 || strlen(s) == 1 ? VAR : FUN;
}
s[i] = 0;