Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6.     freopen("program_with_comments.c", "r", stdin);
  7.     freopen("output.c", "w", stdout);
  8.     char c;
  9.  
  10.     int state = 0;
  11.  
  12.  
  13.     while ((c = getchar()) != EOF)
  14.     {
  15.         switch(state)
  16.         {
  17.         case 0:
  18.             if (c == '/')
  19.                 state = 1;
  20.             else if (c == '"')
  21.                 state = 4;
  22.             break;
  23.         case 1:
  24.             if (c == '*')
  25.                 state = 2;
  26.             else
  27.                 state = 0;
  28.             break;
  29.         case 2:
  30.             if (c == '*')
  31.                 state = 3;
  32.             break;
  33.         case 3:
  34.             if (c == '/') {
  35.                 state = 0;
  36.                 continue;
  37.             }
  38.             else if (c != '*')
  39.                 state = 2;
  40.             break;
  41.         case 4:
  42.             if (c == '"')
  43.                 state = 0;
  44.             break;
  45.         }
  46.  
  47.         if (state == 0 || state == 4)
  48.             putchar(c);
  49.     }
  50.     return 0;
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement