|
#include<stdio.h>
#include<string.h>
struct score
{signed math;
signed english;
signed computer;};
struct student
{char num[13];
char name[25];
char sex;
int birth;
struct score sco;};
XIUGAI()
{
FILE *fp;
struct student stu[15];
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 score must 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[15],stu1[15],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);
}
运行时出错,说是没有";" 晕啊,找了老半天也没发现错在哪里,高手帮小弟一下啊 |
|