diff options
| author | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-11-23 23:15:15 +0800 |
|---|---|---|
| committer | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-11-23 23:15:15 +0800 |
| commit | a1c7577c6f9fc87aa8a0322431de447d7df0f24d (patch) | |
| tree | 473cb771469f1982b25415bfe9bad1c6e36cd5d6 /1/24.c | |
| parent | 9027acd597bc3da980d38efaed3383aa57696592 (diff) | |
| download | k&r-exercises-a1c7577c6f9fc87aa8a0322431de447d7df0f24d.tar.gz | |
1.24
Diffstat (limited to '1/24.c')
| -rw-r--r-- | 1/24.c | 21 |
1 files changed, 7 insertions, 14 deletions
@@ -18,25 +18,16 @@ int main(int argc, char *argv[]) { for (i = 0; i < MAXLEN - 1 && (c = getchar()) != EOF; i++) { if (!comment && !quote && (c == '/' || c == '*') && p == '/') { comment = c == '/' ? INLINE : MULTILINE; - continue; - } - if (!comment && !quote && c == '"') { + } else if (!comment && !quote && c == '"') { quote = TRUE; - continue; - } - if (comment == INLINE && c == '\n') { + } else if (comment == INLINE && c == '\n') { comment = FALSE; - continue; - } - if (comment == MULTILINE && c == '/' && p == '*') { + } else if (comment == MULTILINE && c == '/' && p == '*') { comment = FALSE; - continue; } if (!comment && quote && c == '"' && p != '\\') { quote = FALSE; - continue; - } - if (!comment && !quote) { + } else if (!comment && !quote) { if (c == '{') braces++; else if (c == '(') @@ -50,6 +41,8 @@ int main(int argc, char *argv[]) { else if (c == ']') bracks--; } + + p = c; } if (braces != 0) @@ -60,7 +53,7 @@ int main(int argc, char *argv[]) { printf("err: input contains %d open brackets\n", bracks); if (braces == 0 && parens == 0 && bracks == 0) - printf("all braces, parenthese and brackets are balanced!\n"); + printf("no basic syntax errors!\n"); return 0; }
\ No newline at end of file |
