Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- double x=1/3;
- /* this is multiline comment,
- * continuing here...
- * and here...
- */
- // this is a single line comment
- int main()
- {
- printf("Comment remover: insert C code, end=CTRL+Z\n");
- enum { START, SLASH, MULTILINE,
- END_OF_MULTILINE, SINGLELINE} state=START;
- int c;
- while ((c=getchar())!=EOF) {
- switch (state) {
- case START:
- if (c=='/') {
- state=SLASH;
- } else {
- putchar(c);
- }
- break;
- case SLASH:
- if (c=='*') {
- state=MULTILINE;
- } else if (c=='/') {
- state=SINGLELINE;
- } else {
- putchar('/');
- putchar(c);
- state=START;
- }
- break;
- case MULTILINE:
- if (c=='*') {
- state=END_OF_MULTILINE;
- }
- break;
- case END_OF_MULTILINE:
- if (c=='/') {
- state=START;
- } else {
- state=MULTILINE;
- }
- break;
- case SINGLELINE:
- if (c=='\n') {
- putchar(c);
- state=START;
- }
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement