突然发现的这个有关问题 .一眼看不出来,运行错后也很难找到异常之处,等你来战?
突然发现的这个问题 .一眼看不出来,运行错后也很难找到错误之处,等你来战??

代码在下面:
#include"stdio.h"
main()
{
typedef struct
{
int num;
char name[20];
char sex;
float score;
}student;
student stu1;
scanf("%d",&stu1.num);
scanf("%s",stu1.name);
scanf("%c",&stu1.sex);
scanf("%f",&stu1.score);
printf("%d\n%s\n%c\n%.1f\n",stu1.num,stu1.name,stu1.sex,stu1.score);
}
来看看吧
------解决思路----------------------
是啊,scanf()在输入字符的时候会把回车当成输入,相邻两个输入字符的scanf()需要在后一个scanf()加空格
scanf("%c",&a)
scanf(" %c",&b)
代码在下面:
#include"stdio.h"
main()
{
typedef struct
{
int num;
char name[20];
char sex;
float score;
}student;
student stu1;
scanf("%d",&stu1.num);
scanf("%s",stu1.name);
scanf("%c",&stu1.sex);
scanf("%f",&stu1.score);
printf("%d\n%s\n%c\n%.1f\n",stu1.num,stu1.name,stu1.sex,stu1.score);
}
来看看吧
------解决思路----------------------
是啊,scanf()在输入字符的时候会把回车当成输入,相邻两个输入字符的scanf()需要在后一个scanf()加空格
scanf("%c",&a)
scanf(" %c",&b)