scanf("%d,%s,%f",&student1.num,&student1.name,&student1.score);
scanf("%d,%s,%f",&student2.num,&student2.name,&student2.score);
上面这2句不对,可以编译成功,但是保存的值是错误的,
因为它会把“逗号”当作字符送给了%s,所以最后面的%d没有输入数据。
可以换成空格。
scanf() 开始读取输入以后,会在遇到的第一个空白字符空格(blank)、制表符(tab)或者换行符(newline)处停止读取。
#include
struct Student
{
int num;
char name[20];
float score;
};
void main()
{
struct Student student1,student2;
scanf("%d %s %f",&student1.num,&student1.name,&student1.score);
scanf("%d %s %f",&student2.num,&student2.name,&student2.score);
if(student1.score>student2.score)
printf("%s(%d):%6.2f\n",student1.name,student1.num,student1.score);
else
printf("%s(%d):%6.2f\n",student2.name,student2.num,student2.score);
}