题目:编写一个print函数,打印5个学生的数据记录。每个记录包括num,name,score.
#include <stdio.h>
struct student
{
char num[7];
char name[20];
float score;
};
struct student data[5]={
{"0124301","hanjia",99.5},
{"0124302","hanbaogang",98.5},
{"0124303","gaobo",95},
{"0124304","huwei",99},
{"0124305","wangyu",98},
};
//打印学生数据记录
void print(struct student a[5])
{
int i;
for(i=0;i<5;i++)
printf("%s-%s-%3.1f\n",a[i].num,a[i].name,a[i].score);
}
main()
{
print(data);
//getch();
}
编译后的运行结果是:
0124301hanjia-hanjia-99.5
0124302hanbaogang-hanbaogang-98.5
0124303gaobo-gaobo-95
0124304huwei-huwei-99
0124305wangyu-wangyu-98
为什么name会输出两次呢?不解!