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 comments Message-ID: <1486@wpi.wpi.edu> Date: 24 Mar 89 01:14:44 GMT References: <1167@unisec.usi.com> <5312@turnkey.TCC.COM> <1989Jan30.013936.11995@gpu.utcs.toronto.edu> <13048@steinmetz.ge.com> <1989Jan31.021121.13816@gpu.utcs.toronto.edu> Reply-To: lfoard@wpi.wpi.edu (Lawrence C Foard) Organization: Worcester Polytechnic Institute, Worcester, MA. USA Lines: 52 oops. It appears that the original posting had a bug /** **/ blew up here is a fixed version. Why is this program better than LEX?? Because it is free there are still some people who use PC and buy there own software. --------------Cut here--------------- /* Public domain C comment stripper created by Lawrence Foard */ /* version 2 */ #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 { c=0; do { ungetc(c,stdin); while(getc(stdin)!='*'); } while((c=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.