Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ulowell!m2c!wpi!lfoard From: lfoard@wpi.wpi.edu (Lawrence C Foard) Newsgroups: comp.lang.c Subject: C comment stripper Message-ID: <1453@wpi.wpi.edu> Date: 22 Mar 89 03:51:24 GMT References: <1842@viper.Lynx.MN.Org> <9543@smoke.BRL.MIL> Reply-To: lfoard@wpi.wpi.edu (Lawrence C Foard) Organization: Worcester Polytechnic Institute, Worcester, MA. USA Lines: 47 I just made this C comment stripper, I tried it on it self and it works ok. If any one finds code it pukes on tell me (there is probably still something I missed). ----------------------cut here------------------- /* Public domain C comment stripper created by Lawrence Foard */ #include char *a="/* this is a test 'of the emergency \" comment stripper \\ \'*/"; /* this is a'nasty\' "comment" meant / * to really confuse it"*//*\*/ int no_com() { int c; static int quote=0,squote=0,slash=0; c=getc(stdin); if (slash || (c=='\\')) { slash=!slash; return(c); } if ((quote^=((c=='"') && !squote)) || (squote^=((c=='\''/*\ and right here two \*/) && !quote))) return(c); if (c=='/') if ((c=getc(stdin))!='*') { ungetc(c,stdin); return('/'); } else { do while(getc(stdin)!='*'); while(getc(stdin)!='/'); return(no_com()); } return(c); } main() { int c; while((c=no_com())!=EOF) fputc(c,stdout); } -- Disclaimer: My school does not share my views about FORTRAN. FORTRAN does not share my views about my school.