diff options
| author | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-11-22 19:14:54 +0800 |
|---|---|---|
| committer | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-11-22 19:14:54 +0800 |
| commit | 781c9738c34a22979e6e26fa3a8ad04fd37bdfd0 (patch) | |
| tree | 4956407f4fba7a0d763e26200a5a6f57e7dad1de | |
| parent | 05f202deafbd1684d5314937fa82f9f26defae87 (diff) | |
| download | k&r-exercises-781c9738c34a22979e6e26fa3a8ad04fd37bdfd0.tar.gz | |
1.23
| -rw-r--r-- | 1/23.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -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; |
