您的位置:首页 > 编程语言

编译第一步:去源代码(C)注释

2011-03-04 16:50 211 查看
#include

#include

 
main()

{

    char ch1,ch2,ch3,ch4;

    FILE *fp1,*fp2;

     if((fp1=fopen("D://c programs//常见题//input.txt","r"))==NULL)

    {

        printf("cann't open the input file/n");

        exit(1);

    }

    if((fp2=fopen("D://c programs//常见题//output.txt","w"))==NULL)

    {

        printf("cann't open the output file/n");

        exit(1);

    }

    

    ch1=fgetc(fp1);

    ch2=fgetc(fp1);

    while(!feof(fp1))

    {

        if('/'==ch1 && '/'==ch2)

//这里注意,判断条件要细分好,在设及到条件分支语句时,
//要注意,每个分支都要单独的测试到,会更容易维护
        {

 
            ch3=fgetc(fp1);

            while(!feof(fp1))

            {

                if(10==ch3)

                {

                    fputc(ch3,fp2);

                    break;

                }

                else

                {

                    ch3=fgetc(fp1);

                }

            }

            ch1=fgetc(fp1);

            ch2=fgetc(fp1);

        }

 
        if('/'==ch1 && '*'==ch2)

        {

            ch3=fgetc(fp1);

            ch4=fgetc(fp1);

            while(!feof(fp1))

            {

                if('*'==ch3 && '/'==ch4)

                {

                    ch1=fgetc(fp1);

                    ch2=fgetc(fp1);

                    break;

                }

                else

                {

                    ch3=ch4;

                    ch4=fgetc(fp1);

                }

            }

        }

 
        else

        {

            fputc(ch1,fp2);

            ch1=ch2;

            ch2=fgetc(fp1);

        }

    }

    fputc(ch1,fp2);

    fclose(fp1);

    fclose(fp2);

    return 1;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: