From a1c7577c6f9fc87aa8a0322431de447d7df0f24d Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Tue, 23 Nov 2021 23:15:15 +0800 Subject: 1.24 --- 1/24.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to '1/24.c') diff --git a/1/24.c b/1/24.c index 08107e1..0e8e53f 100644 --- a/1/24.c +++ b/1/24.c @@ -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 -- cgit v1.2.3