Chinaunix首页 | 论坛 | 博客
  • 博客访问: 267404
  • 博文数量: 47
  • 博客积分: 1516
  • 博客等级: 上尉
  • 技术积分: 507
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-29 09:23
文章分类

全部博文(47)

文章存档

2009年(1)

2008年(3)

2007年(1)

2006年(36)

2005年(6)

分类: C/C++

2006-01-25 09:29:35

C语言圣经

1-23练习题


#include
#include
main()
{
        FILE *fin;
        char *zhushi1="//";
        char *zhushi2="/*";
        char *zhushi3="*/";
        char zhushi[3],zs[2];
        zhushi[2]='';
        char read,tmp;
        char ren[65536];
        int  cc=0;
        int i=0;
        int zslx=0;
        int temp=0;
        int mh=0;
        int inzhushi=0;
        if((fin=fopen("test.c","r"))!=NULL)
        {
                while((read=fgetc(fin))!=EOF)
                {
                        if (cc==2)
                        {
                                zhushi[0]=tmp;
                                zhushi[1]=read;
                                tmp=read;
                                cc=2;
                        }
                        if (cc==1)
                        {
                                zhushi[1]=read;
                                tmp=read;
                                cc=2;
                        }
                        if (cc==0)
                        {
                                zhushi[0]=read;
                                tmp=read;
                                cc=1;
                        }
                        if ((mh==1)&&(read=='"')&&(inzhushi!=1))
                        {
                                mh=0;
                        }
                        if ((mh==0)&&(read=='"')&&(inzhushi!=1))
                        {
                                mh=1;
                        }
                        if ((strcmp(zhushi,zhushi1)==0)&&(inzhushi==0)&&(mh==0))
                        {
                                i--;
                                inzhushi=1;
                                zslx=1;
                                continue;
                        }
                        if((strcmp(zhushi,zhushi2)==0)&&(inzhushi==0)&&(mh==0))
                        {
                                i--;
                                zslx=2;
                                inzhushi=1;
                                continue;
                        }
                        if ((inzhushi==1)&&(strcmp(zhushi,zhushi3)==0)&&(zslx==2))
                        {
                                i=i-2;
                                inzhushi=0;
                                zslx=0;
                                continue;
                        }
                        if ((read=='n')&&(zslx==1)&&(inzhushi==1))
                        {
                                i=i-2;
                                inzhushi=0;
                                zslx=0;
                                continue;
                        }
                        if ((inzhushi==0)&&(zslx==0))
                        {
                                ren[i]=read;
                                i++;
                        }
                }
                fclose(fin);
                ren[i]='';
                printf("%sn",ren);
        }
        else
        {
                printf("file not found!!!n");
        }
}
阅读(2879) | 评论(3) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2009-06-14 10:40:15

456

chinaunix网友2008-01-03 15:05:17

没带注释啊