#include"stdio.h"
#include"stdlib.h"
int main()
{
FILE *fp1,*fp2, *fp3;
char ch1,ch2,ch3,ch4;
int flag1=0, flag2 = 0, flag3 = 0, flag4 = 0, flag5 = 0;
int i = 0;
int flag6 = 0;
if((fp1=fopen("input.cpp","r"))==NULL)
{
printf("file cannot be opened\n");
exit(1);
}
if((fp2=fopen("output.cpp","w"))==NULL)
{
printf("file cannot be writed\n");
exit(1);
}
printf("处理前\n");
while((ch1=fgetc(fp1))!=EOF)
{
printf("%c",ch1);
if(ch1 == '/' && flag1 == 0 && flag5 == 0 && flag6 == 0)
{
flag1 = 1;
continue;
}
else if(ch1 == '/' && flag1 == 1 && flag6 == 0)
{
flag3 = 1;
flag1 = 0;
continue;
}
else if(ch1 == '*' && flag1 == 1 && flag6 == 0)
{
flag4 = 1;
flag1 = 0;
continue;
}
else if(ch1 == '"' && flag6 == 0)
{
flag6 = 1;
}
else if(ch1 == '"' && flag6 == 1)
{
flag6 = 0;
}
if(flag3 == 1)
{
if(ch1 != '\n')
{
continue;
}
else
{
flag3 = 0;
}
}
if(flag4 == 1)
{
if(ch1 != '*' && flag5 != 1)
{
continue;
}
else if( ch1 == '*')
{
flag5 = 1;
continue;
}
if(flag5 == 1 && ch1 == '/')
{
flag4 = 0;
flag1 = 0;
flag3 = 0;
flag5 = 0;
continue;
}
}
fputc(ch1,fp2);
}
fclose(fp1);
fclose(fp2);
return 0;
}