C comment stripper
Lawrence C Foard
lfoard at wpi.wpi.edu
Wed Mar 22 13:51:24 AEST 1989
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 <stdio.h>
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.
More information about the Comp.lang.c
mailing list