diff options
| author | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-12-16 17:52:34 +0800 |
|---|---|---|
| committer | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-12-16 17:52:34 +0800 |
| commit | 5ba4e0e4751e69021fb180a859370609ec0f73e2 (patch) | |
| tree | 2b8e97073dbf01017e1160c5dc03daee81cf649b /4 | |
| parent | 19ef1c01b28a720217978c02b363d2bccfc99563 (diff) | |
| download | k&r-exercises-5ba4e0e4751e69021fb180a859370609ec0f73e2.tar.gz | |
4.10
Diffstat (limited to '4')
| -rw-r--r-- | 4/10.c | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -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; |
