diff options
author | sinanmohd <pcmsinan@gmail.com> | 2022-06-04 12:11:15 +0530 |
---|---|---|
committer | sinanmohd <pcmsinan@gmail.com> | 2022-06-04 12:11:15 +0530 |
commit | c24973af02bc33f2f5f25d37e22ca91da5de3c47 (patch) | |
tree | 460a005b6a3a9a967bd881bc2bf01e0becbe33cc /1.23.c |
inital commit
Diffstat (limited to '1.23.c')
-rw-r--r-- | 1.23.c | 56 |
1 files changed, 56 insertions, 0 deletions
@@ -0,0 +1,56 @@ +#include <stdio.h> + +#define OUT 0 +#define STAR 1 +#define SLASH 2 + +/* this is a c programm to remove all comments from c programms */ +// including "slash comments" +/* and "star comments" */ +// without the use of arrays + +int +main(void) +{ + char input, temp; + int state; + + state = OUT; + + while ((input = getchar()) != EOF) { + + if (input == '/') { + temp = input; + + if ((input = getchar()) == '*') + state = STAR; + else if (input == '/') + state = SLASH; + else + printf("%c", temp); + + } + + else if (input == '*' && state == STAR) { + + if ((input = getchar()) == '/') { + state = OUT; + + if ((input = getchar()) != '\n') + printf("%c", input); + + continue; + } + } + + else if (input == '\n' && state == SLASH) { + state = OUT; + continue; + } + + if (state == OUT) + printf("%c", input); + } + + return 0; +} |