马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 945402287 于 2013-10-10 15:12 编辑 #include<stdio.h>
struct stu
{
int num;
char name[20];
float score;
};
void main()
{
struct stu *findp( int number, struct stu *sp );
struct stu student[5] = { { 1001, "Li ping", 55 }, { 1002, "zhang ping", 80 }, { 1003, "wang feng", 75 }, { 1004, "cheng lin", 82 }, { 1005, "wu yong", 94 } };
int fnum;
int i;
struct stu *sap;
printf("Enter the number:");
scanf("%d", &fnum);
sap = findp( fnum, student );
if ( sap -> num != NULL )
{
printf("number:%d\n", sap -> num);
printf("name:%s\n", sap -> name);
printf("Score:%f\n", sap -> score);
}
else
printf("Not found\n");
}
struct stu *findp( int number, struct stu *sp )
{
int i;
struct stu *stemp = NULL;
for ( i = 0; i < 5; i++, sp++ )
if ( sp -> num == number )
{
stemp = sp;
break;
}
return ( stemp );
}
运行之后输入1006不是显示的Not found 而是出错了 这是为什么呢
|