帮忙看一个C程序,结果不如自己所想

类别:编程语言 点击:0 评论:0 推荐:

题目:编写一个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会输出两次呢?不解!

本文地址:http://com.8s8s.com/it/it22011.htm