superkamiu 发表于 2005-12-28 18:20

调试高手进来看看啊,小弟没办法了!

#include<stdio.h>
#include<string.h>
struct score
{signed math;
   signed english;
   signed computer;};
struct student
   {char num;
    char name;
    char sex;
    int birth;
    struct score sco;};
XIUGAI()
{
        FILE *fp;
        struct student stu;
        struct student xiugai;
        struct student *p;
        int z=sizeof(struct student),i;
        char k='y',cha='n';
        p=stu;
        if((fp=fopen("student.dat","r+b"))==NULL)
        {
                printf("\nERROR opening student file");
                getch();
                return;
        }

        while(k=='y')
        {
                clrscr();
                printf("\t\tMODIFY student's information\n\n\n");
                printf("Enter student number (upto 13 chars.):");
                scanf("%s",xiugai.num);
                rewind(fp);
                for(i=0;(fread((p+i),z,1,fp))==1&&cha=='n';i++)
                {
                                if(cha=='y')
                                break;
                        if(strcmp(xiugai.num,(*(p+i)).num)==0)
                        {
                                cha='y';

                        printf("Number:%s\nName:%s\nSex:%C\nbirth:%d\nMath score:%f\nEnglish score:%f\nComputer core:%f\n\n",(*(p+i)).num,(*(p+i)).name,(*(p+i)).sex,(*(p+i)).birth,(*(p+i)).sco.math,(*(p+i)).sco.english+(*(p+i)).sco.computer);
                                printf("\t\tADD NEW STUDENT INFORMATION\n\n");
                printf("Enter student name (upto 25 chars.):");
                scanf("%s",(*(p+i)).name);
                printf("\nEnter student number (upto 13 chars):");
                scanf("%s",(*(p+i)).num);
                printf("\nEnter studen sex(M OR F) :");
                scanf("%c",&(*(p+i)).sex);
                printf("\nEnter studen birth :");
                scanf("%d",&(*(p+i)).birth);
                printf("\nEnter studen math score :");
                scanf("%d",&(*(p+i)).sco.math);
                printf("\nEnter studen english score :");
                scanf("%d",&(*(p+i)).sco.english);
                printf("\nEnter studen computer score :");
                scanf("%d",&(*(p+i)).sco.computer);
                while((*(p+i)).sco.math<0||(*(p+i)).sco.math>100)
                {
                        printf("\n\tstudent math scoremust be between 0 and 100");
                        printf("\nEnter studen math score:");
                        scanf("%ld",&(*(p+i)).sco.math);
                        fflush(stdin);
                }
                while((*(p+i)).sco.english<0||(*(p+i)).sco.english>100)
                {
                        printf("\n\tstudent englsih score must be between 0 and 100");
                        printf("\nEnter studen english score:");
                        scanf("%ld",&(*(p+i)).sco.english);
                        fflush(stdin);
                }
                while((*(p+i)).sco.computer<0||(*(p+i)).sco.computer>100)
                {
                        printf("\n\tstudent computer score must be between 0 and 100");
                        printf("\nEnter studen computer score:");
                        scanf("%ld",&(*(p+i)).sco.computer);}

                                printf("\student information have been added\n");
                                fseek(fp,-z,1);
                                fwrite(&xiugai,z,1,fp);


                }
                fflush(stdin);
                printf("\nhai xiu gai ma?(y/n):");
                scanf("%c",&k);
                cha='n';
        }
        fclose(fp);
}


SHANCHU()


        {struct student stu,stu1,shanchu;
        struct student *p,*p2;
        FILE *fp
        int z=sizeof(struct student),i,j=0;
        char k='y',cha='n',n;
        p=stu;
        p2=stu1;
        if((fp=fopen("student.dat","rb"))==NULL)
        {
                printf("\nERROR opening student file");
                getch();
                return;
        }

        while(k=='y')
        {
                clrscr();
                printf("\t\tDELETE student information\n\n\n");
                printf("Enter Student number (upto 13 chars.):");
                scanf("%s",shanchu.num);
                rewind(fp);
                for(i=0;(fread((p+i),z,1,fp))==1&&cha=='n';i++)
                {
                        if(strcmp(shanchu.num,(*(p+i)).num)==0)
                        {
                                printf("Number:%s\nName:%s\nSex:%C\nbirth:%d\nMath score:%f\nEnglish score:%f\nComputer core:%f\n\n",(*(p+i)).num,(*(p+i)).name,(*(p+i)).sex,(*(p+i)).birth,(*(p+i)).sco.math,(*(p+i)).sco.english(*(p+i)).sco.computer);
                                printf("shan chu ma (y/n)?:");
                                fflush(stdin);
                                scanf("%c",&n);
                        }
                        else
                        {
                                *(p2+j)=*(p+i);
                                j++;
                        }
                }
                if(n=='y')
                {
                        printf("The Student information have been deleted");
                        fclose(fp);
                        if((fp=fopen("student.dat","wb"))==NULL)
                        {
                                printf("\nERROR opening student file");
                                getch();
                                return;
                        }
                        fflush(fp);
                        for(i=0;i<j;i++)
                        fwrite(p2+i,z,1,fp);
                }
                fflush(stdin);
                printf("\nhai shan chu ma? (y/n):");
                scanf("%c",&k);
        }
        fclose(fp);
}
运行时出错,说是没有";" 晕啊,找了老半天也没发现错在哪里,高手帮小弟一下啊

superkamiu 发表于 2005-12-28 18:23

以上是main()里的两个定义涵数,高手们帮看一下

wool王 发表于 2005-12-28 21:19

楼主好像有点依赖心理。

建议你自己调试,然后将中间信息错误信息还有自己的疑问或看法贴出来,这样大家比较容易帮你,同时你才可以真正学到东西。

要不像你这样全部源程序贴出来,想帮你的人看得费劲,就算帮了你你也学不到东西,更浪费了帮你的人的时间。

jackvenn 发表于 2005-12-28 22:21

最讨厌没有注释的代码了.

superkamiu 发表于 2005-12-29 10:08

呵呵,是是是,各位批评的是,要不怎么说小弟是新手呢,3楼的大哥真是厉害,一看就看出了我的依赖心理,是的,是有点,只是因为时间太赶了,想得到高手们的帮忙,知道错了,下次一定改!
   还有就是注释的问题,不是我不想注释,只是如果要在这贴子上注释就太浪费时间了,(我知道这样又会浪费帮我的人的时间),要是写在程序里的话,我用的是纯C.里面不允许出现中文字符,各位是知道的.

superkamiu 发表于 2005-12-29 10:10

我觉得3楼大哥说的很有道理,小弟听进去了!念小弟初犯,给次机会啊,不要这样就不理人了啊,好不好?呵呵.........

jackvenn 发表于 2005-12-29 10:45

在程序中写注释是一种好习惯.

谁说c不可以用中文注释的?

别当我没用过c呀.怎么说我也用tc用了一段时间的啦.

在/* */里就可以写啦嘛.

只是你在tc里显示是乱码而已.

但是在记事本里还是可以看得到的呀.

superkamiu 发表于 2005-12-29 13:12

哦,原来是这个意思,这样的话,小弟会,恩,小弟记下了,呵呵,又学了一招!
页: [1]
查看完整版本: 调试高手进来看看啊,小弟没办法了!