程序去注释

#include<stdio.h>

int main()
{
    FILE *fp_read,*fp_write;
    fp_read=fopen("in.cpp","r");
    fp_write=fopen("out.cpp","w");
    bool yinhao=false;
    char c;
    while(!feof(fp_read)){
        c=fgetc(fp_read);
        if(c=='"') yinhao=!yinhao;
        if('/'==c){
            if(yinhao){
                fputc(c,fp_write);
            }
            else{
                c=fgetc(fp_read);
                if(c=='/'){
                    while(c!='n') c=fgetc(fp_read);
                }
                if(c=='*'){
                    char old;
                    old=fgetc(fp_read);
                    for(;;){
                        c=fgetc(fp_read);
                        if(old=='*'&&c=='/') break;
                        old=c;
                    }
                }
            }
        }
        else{
            fputc(c,fp_write);
        }
    }
    fclose(fp_read);
    fclose(fp_write);
}

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*
*
Website