一时手痒,抄了书上一个实例!运行报错!实在检查不出错哪儿了!
#include<stdio.h>typedef struct student{
int id;
char name[10];
float score;
}student;
int search(student stu[],int n,int key){
int i;
for(i=0;i<n;i++)
if(stu[i].id==key)
return i;
}
main()
{
student stu[4]={{1004,"TOM",100},{1002,"LILY",95},
{1001,"ANN",93},{1003,"LUCY",98}
};
int addr;
addr=search(stu,4,1001);
printf("student ID: %d\n",stu[addr].id);
printf("student name: %s\n",stu[addr].name);
printf("student score: %f\n",stu[addr].score);
getche();
}