done shellcomments exercise

This commit is contained in:
Tommaso Rodolfo Masera 2019-08-04 14:54:41 +02:00
parent 10357425fc
commit 91bb9d5532
1 changed files with 24 additions and 0 deletions

24
shellcomments.c Normal file
View 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;
}