|
I used the structure for the first time and wrote a program, which compiles and links normally. It ’s just that the result is different from the input. Something is added. After searching for a long time, I ca n’t figure out the problem there.
#include "stdio.h"
struct person {
char name [20];
char sex [20];
int age;
};
struct student {
int number;
int score;
struct person roommate;
};
void main ()
{
int i;
Struct student myroommate [4];
printf ("---------------- Three classes in the department of family planning ---------------------\n");
printf ("Please enter the student number, grade, name, gender, age of your dormitory member:\n");
printf ("----------- Note that the input parts are separated by ',' -----------\n");
for (i = 0; i <4; i ++)
{
scanf ("% d,% d,% s,% s,% d",
&myroommate [i] .number,
&myroommate [i] .score,
&myroommatei] .roommate.name,
&myroommatei] .roommate.sex,
&myroommate [i] .roommate.age);
}
printf ("Student number, grade, name, gender, and age of dormitory members are:\n");
for (i = 0; i <4; i ++)
{
printf ("% d,% d,% s,% s,% d\n",
myroommate [i] .number, myroommate [i] .score,
myroommate [i] .roommate.name,
myroommate [i] .roommate.sex,
myroommate [i] .roommate.age);
}
}
The output is a little garbled per line. |
|