summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-11-23 23:15:15 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-11-23 23:15:15 +0800
commita1c7577c6f9fc87aa8a0322431de447d7df0f24d (patch)
tree473cb771469f1982b25415bfe9bad1c6e36cd5d6
parent9027acd597bc3da980d38efaed3383aa57696592 (diff)
downloadk&r-exercises-a1c7577c6f9fc87aa8a0322431de447d7df0f24d.tar.gz
1.24
-rw-r--r--1/24.c21
1 files changed, 7 insertions, 14 deletions
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