From 781c9738c34a22979e6e26fa3a8ad04fd37bdfd0 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Mon, 22 Nov 2021 19:14:54 +0800 Subject: 1.23 --- 1/23.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/1/23.c b/1/23.c index fdb4a5b..b27e60f 100644 --- a/1/23.c +++ b/1/23.c @@ -22,10 +22,18 @@ int main(int argc, char *argv[]) { comment = MULTILC; i--; } else { + // try not to add redundant line breaks. + if (i > 0 && s[i - 1] == '\n' && curr == '\n') { + continue; + } s[i++] = curr; } - } else if ((comment == SINGLLC && curr == '\n') || - (comment == MULTILC && curr == '/' && prev == '*')) { + } else if (comment == SINGLLC && curr == '\n') { + comment = NONE; + // try not to add redundant line breaks. + if (s[i - 1] != '\n') + s[i] = '\n'; + } else if (comment == MULTILC && curr == '/' && prev == '*') { comment = NONE; } @@ -34,7 +42,7 @@ int main(int argc, char *argv[]) { s[i] = 0; - printf("c code: \n"); + printf("Code without comments: \n"); printf("%s\n", s); return 0; -- cgit v1.2.3