gwyn@smoke.BRL.MIL (Doug Gwyn ) (03/22/89)
I'm not sure why there is an interest in stripping comments from C source; a more usual problem is getting adequate comments ADDED to C source! Anyway, years ago when I had a similar problem (converting C++-style // comments-to-EOL to C-style /*...*/), I found the easiest way to solve the problem with acceptably high confidence in the correctness of the solution was to design a FSM as a diagram, then implement it as a C getchar() loop with a switch to the case label for the current state, at which the appropriate action (typically a putchar()) would occur and the global state variable would be updated to reflect the correct transition to the next state. Worked like a charm (no, not by magic!).