为何按姓名查找(void anxingming)执行不了?
#include<stdio.h>#include<stdlib.h>
#include<string.h>
#define SIZE 2
struct student_type
{
int num;
char name[20];
int age;
char sex[5];
char date[20];
char addr[40];
int tel;
char email[40];
}stud[SIZE];
int i;
void save()
{
FILE *fp;
int i;
if ((fp=fopen("stu_list.txt","wb"))==NULL)
{
printf("cannot open file\n");
return;
}
for(i=0;i<SIZE;i++)
if(fwrite(&stud[i],sizeof(struct student_type),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
void luru()
{
int i;
for(i=0;i<SIZE;i++)
{
printf("输入学号:\n");
scanf("%d",&stud[i].num);
printf("输入姓名:\n");
scanf("%s",stud[i].name);
printf("输入年龄:\n");
scanf("%d",&stud[i].age);
printf("输入性别:\n");
scanf("%s",stud[i].sex);
printf("输入出生年月:\n");
scanf("%s",stud[i].date);
printf("输入家庭住址:\n");
scanf("%s",stud[i].addr);
printf("输入电话:\n");
scanf("%d",&stud[i].tel);
printf("输入电子邮箱:\n");
scanf("%s",stud[i].email);
}
save();
}
void liulan()
{
int i;
FILE *fp;
fp=fopen("stu_list.txt","rb");
for(i=0;i<SIZE;i++)
{
fread(&stud[i],sizeof(struct student_type),1,fp);
printf("%6d%7s%5d%5s%8s%15s%10d%15s\n",stud[i].num,stud[i].name,stud[i].age,stud[i].sex,stud[i].date,stud[i].addr,stud[i].tel,stud[i].email);
}
fclose(fp);
}
void anxuehao()
{
int a;
char c;
unsigned b;
FILE *fp;
fp=fopen("stu_list.txt","rb");
do
{
printf("学生学号:\n");
scanf("%d",&b);
for(a=0;a<SIZE;a++)
{
if(stud[a].num==b)
{
printf("%6d%7s%5d%5s%8s%15s%10d%15s\n",stud[a].num,stud[a].name,stud[a].age,stud[a].sex,stud[a].date,stud[a].addr,stud[a].tel,stud[a].email);
}
}
}
while(!c);
}
void anxingming()
{
int m;
char name;
FILE *fp;
fp=fopen("stu_list.txt","rb");
printf("请输入姓名:\n");
scanf("%s",name);
for(m=0;m<SIZE;m++)
if(strcmp(name,stud[m].name)==0)
{
printf("%6d%7s%5d%5s%8s%15s%10d%15s\n",stud[m].num,stud[m].name,stud[m].age,stud[m].sex,stud[m].date,stud[m].addr,stud[m].tel,stud[m].email);
}
}
void shanchu()
{
}
void xiugai()
{
}
void main()
{
int x;
do
{
printf("1.录入\n");
printf("2.浏览\n");
printf("3.按学号查询\n");
printf("4.按姓名查询\n");
printf("5.学生信息的删除\n");
printf("6.学生信息的修改\n");
scanf("%d",&x);
switch(x)
{
case 1:luru();break;
case 2:liulan();break;
case 3:anxuehao();break;
case 4:anxingming();break;
case 5:shanchu();break;
case 6:xiugai();break;
case 7:break;
}
}
while(x!=7);
}