Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!hc!lanl!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: stripping comments from C source Message-ID: <9893@smoke.BRL.MIL> Date: 22 Mar 89 03:36:26 GMT References: <7150@siemens.UUCP> <9900010@bradley> <4896@cbnews.ATT.COM> <3145@nunki.usc.edu> <3163@nunki.usc.edu> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 11 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!).