|
#include <stdio.h>
struct person
{
char name[20];
char sex[3];
int age;
};
struct student
{
char number[10];
int score;
struct person roommate;
};
void main()
{
int i;
struct student myroommate[2];
printf("----------------The third class of the Department of Accounting---------------------\n");
printf("Please enter the student ID, grade, name, gender, age of your dormitory member:\n");
printf("-----------Note that each part of the input is separated by','-----------\n");
for(i=0;i<2;i++)
{
printf("student number:");
scanf("%s",myroommate[i].number);
printf("score:");
scanf("%d",&myroommate[i].score);
printf("Name:");
scanf("%s",myroommate[i].roommate.name);
fflush(stdin);
printf("Gender:");
scanf("%s",myroommate[i].roommate.sex);
fflush(stdin);
printf("age:");
scanf("%d",&myroommate[i].roommate.age);
}
printf("The student ID, grade, name, gender, and age of the dormitory members are:\n");
for(i=0;i<2;i++)
{
printf("student ID:%s, grade:%d, name:%s, gender:%s, grade:%d\n",
myroommate[i].number,
myroommate[i].score,
myroommate[i].roommate.name,
myroommate[i].roommate.sex,
myroommate[i].roommate.age);
}
}
How about this time? The main reason is that LZ did not clear STDIN\n. There is no problem on my machine, but there is no fault-tolerant processing for input! ! ! ! |
|