发个自己写的程序上来求指导
#include<stdio.h>#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<conio.h>
#define stud struct student
stud
{
char name[20];
char sex;
long number;
int math;
int c;
int english;
}stu;
void Input(stud *p)
{
scanf("%s\n",stu.name);
scanf("%s\n",&stu.sex);
scanf("%d\n",&stu.number);
scanf("%d\n",&stu.math);
scanf("%d\n",&stu.c);
scanf("%d\n",&stu.english);
}
void showstu(stud *p)
{
printf("%s\n",stu.name);
printf("%s\n",stu.sex);
printf("%d\n",stu.number);
printf("%d\n",stu.math);
printf("%d\n",stu.c);
printf("%d\n",stu.english);
}
void Output(stud *p)
{
FILE *fp;
stud stu;
if((fp=fopen("file.1","rb"))==NULL)
{
printf("eroor could not open");
exit(0);
}
while(!feof(fp))
{
showstu(&stu);
fread((char *)&stu,sizeof(stud),1,fp)
}
void addstu()
{
FILE *fp;
stud stu;
if(fp=fopen("file.1","wb")=NULL)
{
printf("file open error");
exit(0);
}
intput(&stu);
fwrite((char *)&stu,sizeof(stud),1,fp)
fcolse(fp);
}
void Information()
{
int a,i,k;
char j[20];
stud studd[77];
FILE *fp;
if(fp=fopen("file.1","rb")=NULL)
{
printf("file open error");
exit(0);
}
fread(studd,sizeof(stud),77,fp)
fclose(fp);
printf("***********Use Name(1)**********\n");
printf("***********Use Number(2)*********\n");
scanf("%d\n",a);
if(a==1)
{
scanf("%s\n",&j);
for(i=0;i<77;i++)
{
if(strcmp(j,stu[i].name)==0)
printf("%s\t%s\t%ld\t%d\t%d\t%d\t",studd[i].name,studd[i].sex,studd[i].number,studd[i].math,studd[i].c,studd[i].english);
}
}
if(a==2)
{
scanf("%d\n",k);
for(i=0;i<77;i++)
{
if(st u[i].number==k)
printf("%s\t%s\t%ld\t%d\t%d\t%d\t",studd[i].name,studd[i].sex,studd[i].number,studd[i].math,studd[i].sub.c,studd[i].english);
}
}
if(a!=(1||2))
printf("***********Error,Sign Out**************\n");
}
void Summation()
{ int a,b,j,k,i,sum,sum1,sum2,sum3;
printf("********Personal(1)*********\n");
printf("********Subject(2)********\n");
scanf("%d\n",a);
if(a==1)
{
printf("*********Please Input Serial Number**********\n");
scanf("%d",i);
sum=(studd[i].math+studd[i].c+studd[i].english);
printf("%s,%d\n",studd[i].name,sum);
}
if(a==2)
{
printf("*********math(1)***********\n");
printf("*********c(2)***********\n");
printf("*********english(3)***********\n");
scanf("%d\n",b);
if(b==1)
{
for(j=0;j<77;j++)
sum1=sum+studd[i].math;
printf("math of sum=%d\n",sum);
}
if(b==2)
{
for(j=0;j<77;j++)
sum2=sum+studd[i].c;
printf("c of sum=%d\n",sum);
}
if(b==3)
{
for(j=0;j<77;j++)
sum3=sum+studd[i].english;
printf("english of sum=%d\n",sum);
}
}
if(a!=(1||2))
printf("***********Error,Sign Out**************\n");
}
void Average()
{
stud studd[77];
int a,b,j,k,i,sum,sum1,sum2,sum3;
float average,average1,average2,average3;
printf("********Personal(1)*********\n");
printf("********Subject(2)********\n");
scanf("%d\n",a);
if(a==1)
{
printf("*********Please Input Serial Number**********\n");
scanf("%d",i);
sum=(stu[i].sub.math+studd[i].sub.c+studd[i].english);
average=(sum/3);
printf("%s,%f\n",stu[i].name,average);
}
if(a==2)
{
printf("*********math(1)***********\n");
printf("*********c(2)***********\n");
printf("*********english(3)***********\n");
scanf("%d\n",b);
if(b==1)
{
for(j=0;j<77;j++)
sum1=sum+stu[i].sub.math;
average1=(sum1/3);
printf("math of average=%f\n",average1);
}
if(b==2)
{
for(j=0;j<77;j++)
sum2=sum+studd[i].c;
average2=(sum2/3);
printf("c of average=%f\n",average2);
}
if(b==3)
{
for(j=0;j<77;j++)
sum3=sum+studd[i].english;
average3=(sum3/3);
printf("english of average=%f\n",average3);
}
}
if(a!=(1||2))
printf("***********Error,Sign Out**************\n");
}
int main()
{
int i,j;
i=1;
printf("welcome to\n");
printf("***********Input(1)***********\n");
printf("***********Output(2)***********\n");
printf("***********Find Information(3)***********\n");
printf("***********Scroe Summation(4)***********\n");
printf("***********Score Average(5)***********\n");
printf("***********Sign Out(6)*************\n");
printf("**Be Careful:You Must First Input**\n");
do
{
scanf("%d\n",&j);
switch(j)
{
case 1: {Input();printf("**********complete************\n");break;}
case 2: {Output();printf("**********complete************\n");break;}
case 3: {Information();printf("**********complete************\n");break;}
case 4: {Summation();printf("**********complete************\n");break;}
case 5: {Average();printf("**********complete************\n");break;}
case 6: {printf("**********Thank You To Use************\n");break;}
}
}while(j!=6);
return 0;
}