summaryrefslogtreecommitdiffstats
path: root/4/10.c
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-12-16 17:52:34 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-12-16 17:52:34 +0800
commit5ba4e0e4751e69021fb180a859370609ec0f73e2 (patch)
tree2b8e97073dbf01017e1160c5dc03daee81cf649b /4/10.c
parent19ef1c01b28a720217978c02b363d2bccfc99563 (diff)
downloadk&r-exercises-5ba4e0e4751e69021fb180a859370609ec0f73e2.tar.gz
4.10
Diffstat (limited to '4/10.c')
-rw-r--r--4/10.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/4/10.c b/4/10.c
index 36f038a..39119d2 100644
--- a/4/10.c
+++ b/4/10.c
@@ -116,19 +116,29 @@ int getop(char s[]) {
s[1] = 0;
// special characters and operators
- if (c == 0 || c == '+' || c == '*' || c == '/' || c == '%' || c == '=' ||
+ if (c == 0 || c == '+' || c == '*' || c == '/' || c == '%' ||
(c == '-' && isdigit(line[idx + 1])) || c == EOF)
return c;
i = 0;
-
+
if (isdigit(c) || c == '-' || (c == '.' && isdigit(line[idx + 1]))) {
- while (isdigit((s[++i] = c = line[idx++])) || (c == '.' && isdigit(line[idx + 1])))
+ while (isdigit((s[++i] = c = line[idx++])) ||
+ (c == '.' && isdigit(line[idx + 1])))
;
return NUM;
}
-
+ if (isalpha(c) && line[idx + 1] == ' ' && line[idx + 2] == '=') {
+ idx += 2;
+ return '=';
+ }
+
+ while (isalnum(s[++i] = c = line[idx++]))
+ ;
+ s[i] = 0;
+
+ return strcmp("LOUT", s) == 0 ? VAR : FUN;
}
int sp = 0;