hello! i can't get the right output, it says "EOFERROR: EOF when reading a line" Instructions: In the code editor, you are provided with the definition of a struct Person. This struct needs an integer value for its age and character value for its gender. Furthermore, you are provided with a displayPerson() function which accepts a struct Person as its parameter. In the main() function, there's a pre-created array of 5 Persons. Your task is to ask the user for the values of the age and gender of these Persons. Then, once you've set their ages and genders, call the displayPerson() function and pass them one by one. here's my code: #include typedef struct { int age; char gender; } Person; void displayPerson(Person); int main(void) { Person persons[5]; for(int i=0;i<5;i++) { printf("Person #%d\n",i+1); printf("Enter Person's age: "); scanf("%d\n",&persons[i].age); printf("\nEnter Person's gender: \n"); scanf("%c\n",&persons[i].gender); } for(int i=0;i<5;i++) displayPerson(persons[i]); return 0; } void displayPerson(Person p) { printf("PERSON DETAILS:\n"); printf("Age: %d\n", p.age); printf("Gender: "); if(p.gender == 'M') { printf("Male"); } else { printf("Female"); } printf("\n\n"); }
hello! i can't get the right output, it says "EOFERROR: EOF when reading a line"
Instructions:
- In the code editor, you are provided with the definition of a struct Person. This struct needs an integer value for its age and character value for its gender. Furthermore, you are provided with a displayPerson() function which accepts a struct Person as its parameter. In the main() function, there's a pre-created array of 5 Persons.
- Your task is to ask the user for the values of the age and gender of these Persons.
- Then, once you've set their ages and genders, call the displayPerson() function and pass them one by one.
here's my code:
#include<stdio.h>
typedef struct {
int age;
char gender;
} Person;
void displayPerson(Person);
int main(void) {
Person persons[5];
for(int i=0;i<5;i++)
{
printf("Person #%d\n",i+1);
printf("Enter Person's age: ");
scanf("%d\n",&persons[i].age);
printf("\nEnter Person's gender: \n");
scanf("%c\n",&persons[i].gender);
}
for(int i=0;i<5;i++)
displayPerson(persons[i]);
return 0;
}
void displayPerson(Person p) {
printf("PERSON DETAILS:\n");
printf("Age: %d\n", p.age);
printf("Gender: ");
if(p.gender == 'M') {
printf("Male");
} else {
printf("Female");
}
printf("\n\n");
}
Step by step
Solved in 2 steps