Advertisement
Guest User

Untitled

a guest
May 19th, 2013
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #define  DEFAULT  0
  3. #define  BLOCK_COMMENT  1
  4. #define  STRING_COMMENT  2
  5. #define  STRING  3  
  6.  
  7. void main()
  8. {
  9.     int c;
  10.     int mode = 0;
  11.     while((c=getchar())!=EOF) {
  12.         switch(mode)
  13.         {
  14.         case DEFAULT:
  15.             if (c == '\"') {
  16.                 mode = STRING;
  17.                 putchar(c);
  18.             } else if (c == '/') {
  19.                 c = getchar();
  20.                 if (c == '/') mode = STRING_COMMENT;
  21.                 else if (c == '*') mode = BLOCK_COMMENT;
  22.                 else putchar('/'), putchar(c);
  23.             } else putchar(c);
  24.             break;
  25.         case BLOCK_COMMENT:
  26.             if (c == '*') if ((c=getchar()) == '/') mode = DEFAULT;
  27.             break;
  28.         case STRING_COMMENT:
  29.             if (c == '\n') mode = DEFAULT, putchar('\n');
  30.             break;
  31.         case STRING:
  32.             if (c == '\\') {
  33.                 putchar(c);
  34.                 putchar(getchar());
  35.              } else if (c == '\"')
  36.                 mode = DEFAULT, putchar(c);
  37.             else putchar(c);
  38.             break;
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement