您的位置:首页 > 其它

33.对学生结构体的数据进行修改

2015-06-12 21:32 106 查看
程序通过定义学生结构体变量,存储了学号、姓名、和3门课的成绩,函数fun的功能是讲形参a中的数据进行修改,把修改后的数据作为函数值返回主函数进行输出。

#include<stdio.h>
#include<string.h>
struct student
{
long sno;
char name[10];
float score[3];

};

struct student fun(struct student a)
{
int i;
a.sno = 1002;
strcpy_s(a.name,10, "LiSi");
for (i = 0;i < 3;i++)
a.score[i]+= 1;
return a;

}
int main()
{
struct student s = { 1001,"ZhangSan",95,80,88 }, t;
int i;
printf("\n\nThe original data:\n");
printf("\nNo:%ld   Name:%s\nScore: ", s.sno, s.name);
for (i = 0;i < 3;i++)
printf("%6.2f", s.score[i]);
printf("\n");
t = fun(s);
printf("\nThe data after modified:\n");
printf("\nNo:%ld  Name :%s\n  Score: ", t.sno, t.name);
for (i = 0;i < 3;i++)
printf("%6.2f", t.score[i]);
printf("\n");
getchar();
return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: