Skip to content

Commit

Permalink
[c_book] ex-1-23-decomment: don't leave newline on fully commented lines
Browse files Browse the repository at this point in the history
  • Loading branch information
ooddaa committed Apr 20, 2024
1 parent e5d8e6b commit 1f13a5d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions c_book/1-ch/exercises/ex-1-23-decomment.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

void rmcomment(char[], int);


/*
* Removes all comments from C code.
*/
Expand Down Expand Up @@ -38,8 +37,10 @@ void rmcomment(char s[], int len) {
int i, prev_c, c;
for (i = 0; i < len && ((prev_c = s[i]) != '/' && (c = s[i + 1]) != '/'); ++i);

s[i] = '\n';
++i;
if (i > 0) {
s[i] = '\n';
++i;
}
s[i] = '\0';
}

Expand All @@ -51,7 +52,6 @@ int main(void)

while ((len = getnextline(s, MAX)) > 0) {
rmcomment(s, len);

printf("%s", s);
}

Expand Down

0 comments on commit 1f13a5d

Please sign in to comment.