summaryrefslogtreecommitdiffstats
path: root/1
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-11-22 19:14:54 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-11-22 19:14:54 +0800
commit781c9738c34a22979e6e26fa3a8ad04fd37bdfd0 (patch)
tree4956407f4fba7a0d763e26200a5a6f57e7dad1de /1
parent05f202deafbd1684d5314937fa82f9f26defae87 (diff)
downloadk&r-exercises-781c9738c34a22979e6e26fa3a8ad04fd37bdfd0.tar.gz
1.23
Diffstat (limited to '1')
-rw-r--r--1/23.c14
1 files 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;