求解,为什么在输入num时就出错,好像只要是遇到输入%d的都会停止工作
#include<stdio.h>struct abc
{
char name[20];
int num;
int math;
}stu;
void main()
{
char c;
int a,b;
c=scanf("%s",stu.name);
a=scanf("%d",stu.num);
b=scanf("%d",stu.math);
printf("%d %d %s",a,b,c);
}
程序代码:#include<stdio.h>
struct abc
{
char name[20];
int num;
float math;//int math;最好定义成float,因为不可能你每次成绩都是整数吧
}stu;
void main()
{
printf("请输入你的信息:");
/*
c=scanf("%s",stu.name); 你定义的C是字符 你stu.name是字符串 你觉得对吗?
a=scanf("%d",stu.num); 输入你不需要加取地址符吗?
b=scanf("%d",stu.math);
*/
scanf("%s%f%d",&stu.name,&stu.math,&stu.num);
printf("%s %.2f %d",stu.name,stu.math,stu.num);
printf("\n");
}
