VC编程,C语言,scanf,printf问题

u013984264 u013984264 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
前面有定义结构体
struct student
{
int num;
char name[10];
int score[3];
};

以下是用3种情况输入一个学生的信息:
第一种:for(i=0;i<1;i++) //name放最后
{
printf("Input the number,name,and three scores of the %dth student:\n",i+1);
scanf("%d,%d,%d,%d,%s",&a[i].num,&a[i].score[0],&a[i].score[1],&a[i].score[2],a[i].name);
}

第二种:for(i=0;i<1;i++) //name不放最后
{
printf("Input the number,name,and three scores of the %dth student:\n",i+1);
scanf("%d,%s",&a[i].num,a[i].name);
scanf("%d",&a[i].score[0]);
scanf("%d",&a[i].score[1]);
scanf("%d",&a[i].score[2]);
}

第三种:for(i=0;i<1;i++) //name不放最后
{
printf("Input the number,name,and three scores of the %dth student:\n",i+1);
scanf("%d,%s,%d,%d,%d",&a[i].num,a[i].name,&a[i].score[0],&a[i].score[0],&a[i].score[0]);
}

打印的话都是用这个语句:for(i=0;i<1;i++)
{
printf("\n输出上面的信息:");
printf("%d,%s,%d,%d,%d",a[i].num,a[i].name,a[i].score[0],a[i].score[1],a[i].score[2]);
}
三种方法分别对应的输出显示情况如下:




但是我最想用的第3种方法,但是后面乱码,请问怎么回事?我猜是scanf的回车键结束引起的,但是不知道它内部怎么读数据的?有大神不?
...全文
评论 6
收藏 已收藏
分享
返回顶部
u013984264
C语言 70,040 成员 243,237 内容