From ce26f83b5871a2459e3d607be007cdb6e86b84e7 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Mon, 22 Nov 2021 20:06:27 +0800 Subject: 1.23 --- 1/23.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to '1/23.c') diff --git a/1/23.c b/1/23.c index 2a563cd..a75b0de 100644 --- a/1/23.c +++ b/1/23.c @@ -3,22 +3,26 @@ #define NONE 0 #define SINGLLC 1 #define MULTILC 2 + #define MAXLEN 1000 /* removes comments from a c program */ int main(int argc, char *argv[]) { - int prev, curr, i, comment; + int prev, curr, i, comment, inquote; char s[MAXLEN]; - i = prev = 0; + inquote = i = prev = 0; comment = NONE; while (i < MAXLEN - 1 && (curr = getchar()) != EOF) { if (!comment) { - if (curr == '/' && prev == '/') { + if (curr == '"' && prev != '\\') { + s[i++] = curr; + inquote = !inquote; + } else if (!inquote && curr == '/' && prev == '/') { comment = SINGLLC; i--; - } else if (curr == '*' && prev == '/') { + } else if (!inquote && curr == '*' && prev == '/') { comment = MULTILC; i--; } else { -- cgit v1.2.3