done shellcomments exercise
This commit is contained in:
parent
10357425fc
commit
91bb9d5532
1 changed files with 24 additions and 0 deletions
24
shellcomments.c
Normal file
24
shellcomments.c
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
int main(int argc, char const *argv[]) {
|
||||||
|
|
||||||
|
int c;
|
||||||
|
bool is_comment;
|
||||||
|
|
||||||
|
while ((c = getchar()) != EOF) {
|
||||||
|
if (c == '#') {
|
||||||
|
is_comment = true;
|
||||||
|
} else if (c != '\n' && is_comment) {
|
||||||
|
putchar(c);
|
||||||
|
} else if (c == '\n' && is_comment) {
|
||||||
|
putchar('\n');
|
||||||
|
is_comment = false;
|
||||||
|
} else {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Reference in a new issue