comment2.c
|
typedef enum { S1, S2, C1, C2 } State; State state = S1; trans(int c) { switch(state){ case S1: if(c == '/') state = S2; break; case S2: if(c == '/') state = S2; else if(c == '*'){ printf("/*"); state = C1; } else state = S1; break; case C1: printf("%c",c); if(c == '*') state = C2; break; case C2: printf("%c",c); if(c == '*') state = C2; else if(c == '/') state = S1; else state = C1; break; } } main() { char buf[1000]; char *s; while(fgets(buf,1000,stdin)){ for(s=buf;*s;s++){ trans(*s); } } }