From 91bb9d55326dcec39debc8bb7cc797561d2fb860 Mon Sep 17 00:00:00 2001 From: tommi27 Date: Sun, 4 Aug 2019 14:54:41 +0200 Subject: [PATCH] done shellcomments exercise --- shellcomments.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 shellcomments.c diff --git a/shellcomments.c b/shellcomments.c new file mode 100644 index 0000000..84cd95c --- /dev/null +++ b/shellcomments.c @@ -0,0 +1,24 @@ +#include +#include + +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; +}