C语言输入5*5数据编写程序实现,c语言编写input()和output()函数输入,输出5个学生的数据记录?...

5b96b6b3856601dfb14f0680b3e0a7d3.png

牧羊人nacy

基于你的代码修改之后,如下:/#includestruct men{int num;char name[8];char sex[8];float score;}boy[5];void input(){int i;for(i=0;i<5;i++){printf("Input the number:\n");scanf("%d",&boy[i].num);printf("Input the name:\n");scanf("%s",boy[i].name);printf("Input the sex:\n");scanf("%s",boy[i].sex);printf("Input the score:\n");scanf("%f",&boy[i].score);}}void output(){int i;for(i=0;i<5;i++){printf("NUM\t\t\tNAME\t\t\tSEX\t\t\tSCORE\n\n");printf("%d\t\t\t",boy[i].num);printf("%s\t\t\t",boy[i].name);printf("%c\t\t\t",boy[i].sex);printf("%.2f\n",boy[i].score);}}int main(){void input();void output();input();output();return (0);}//你之前出错的原因是,struct men里面的name你用的是指针,而你的代码中scanf("%s",boy[i].name);相当于把你输入的字符加载到boy[i].name这个char指针指向的单元;但是这个单元的大小你根本没有设置,所以编译器就报错咯。另外类别我也扩容了。/更新。。。我再自己的电脑上运行了一遍,IDE是Microsoft Visual Studio 9.0你要是要是有问题就问我。我放假了有时间,呵呵。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值