diff options
| author | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-11-23 23:21:22 +0800 |
|---|---|---|
| committer | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-11-23 23:21:22 +0800 |
| commit | a8e49d4b25c75c4392e0ad6e38a543d403567d0a (patch) | |
| tree | fc91bdc957c84adfc9ab3187a8d849a22ae1dbd7 | |
| parent | a1c7577c6f9fc87aa8a0322431de447d7df0f24d (diff) | |
| download | k&r-exercises-a8e49d4b25c75c4392e0ad6e38a543d403567d0a.tar.gz | |
1.24
| -rw-r--r-- | 1/24.c | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -16,16 +16,15 @@ int main(int argc, char *argv[]) { parens = bracks = braces = 0; for (i = 0; i < MAXLEN - 1 && (c = getchar()) != EOF; i++) { - if (!comment && !quote && (c == '/' || c == '*') && p == '/') { - comment = c == '/' ? INLINE : MULTILINE; - } else if (!comment && !quote && c == '"') { - quote = TRUE; - } else if (comment == INLINE && c == '\n') { + if (!comment && !quote) { + if ((c == '/' || c == '*') && p == '/') + comment = c == '/' ? INLINE : MULTILINE; + else if (c == '"') + quote = TRUE; + } else if ((comment == INLINE && c == '\n') || + (comment == MULTILINE && c == '/' && p == '*')) { comment = FALSE; - } else if (comment == MULTILINE && c == '/' && p == '*') { - comment = FALSE; - } - if (!comment && quote && c == '"' && p != '\\') { + } else if (!comment && quote && c == '"' && p != '\\') { quote = FALSE; } else if (!comment && !quote) { if (c == '{') |
