C语言编程问题
我进如数据输入的时候,程序就中止了,为什么!
#include<stdio.h>
#define SIZE 2
struct student
{char name[20];
int xh;
}stud[SIZE];
void save();
int srsj();
int cxsj();
int main();
int gzcx();
int gzcx()
{
int i,a,b,c;
char name[10]={0};
FILE *fp;
if((fp=fopen("stu.dat","rb"))==NULL)
{printf("无法打开此文件\n");
}
printf("\t\t\t<工资清单查询>\n\n\n\t\t\t查看姓名,学号\n");
for(i=0;i<SIZE;i++)
{
fread(&stud[i],sizeof(struct student),1,fp);
printf("\t\t%s\n\t\t%d\n\n",stud[i].name,stud[i].xh);
}
printf("\t\t***************************************\n");
printf("\t\t请输入数字:1:按工号查询\n 2:按姓名查询\n");
printf("\t\t***************************************\n");
printf("你输入的数字:");
scanf("%d\n",&b);
switch(b)
case 1:
{
printf("请输入工号,查看工资清单\n\n");
printf("工号:");
scanf("%d\n",&a);
printf("\t\t<工资清单数据>\n");
for(i=0;i<SIZE;i++)
{
if(stud[i].xh==a)
{
printf("\t\t%s\n\t\t%d\n",stud[i].name,stud[i].xh);
}
}
break;
case 2:
{printf("请输姓中文姓名,查看工资清单\n\n");
printf("姓名:");
scanf("%s",name);
for(i=0;i<SIZE;i++)
{
if(strcmp(name,stud[i].name)==0)
{
printf("\t\t%s\n\t\t%d\n",stud[i].name,stud[i].xh);
}
}
}
}
printf("\n");
printf("\t\t***************************************\n");
printf("\t\t注意:但无法查询时,请按要求操作!或者是无此数据!\n");
printf("\t\t***************************************\n\n\n\n");
fclose(fp);
main();
return 0;
}
void save()
{FILE *fp;
int i;
if((fp=fopen("stu.dat","wb"))==NULL)
{printf("cannot open file \n");
return;
}
for(i=0;i<SIZE;i++)
if(fwrite(&stud[i],sizeof(struct student),1,fp)!=1)
fclose(fp);
}
int srsj()
{int i;
printf("Please enter date of student\n");
for(i=0;i<SIZE;i++)
scanf("%s%d",stud[i].name,stud[i].xh);
save();
return 0;
}
int cxsj()
{int i;
FILE *fp;
if((fp=fopen("stu.dat","rb"))==NULL)
{
printf("cannot open file\n");
}
for(i=0;i<SIZE;i++)
{fread(&stud[i],sizeof(struct student),1,fp);
printf("%s%d\n",stud[i].name,stud[i].xh);
}
fclose(fp);
return 0;
}
int main()
{int a;
printf("\t\t1:进入输入数据\n\t\t2:查询数据\n\t\t3:查询\n");
scanf("%d",&a);
if(a==1)
srsj();
if(a==2)
cxsj();
if(a==3)
gzcx();
;
追问:还是你厉害,我东看西看的,就是 找不出来