Usually I use C++ but was recently given an assignment in C...
here's the assignment:
Declare a structure named Person. The Person structure should have the following fields:
- char name[100];
- int age;
- float gpa;
Write a function with the following signature:
void fill_person(struct Person* per)
Use printf to prompt the user for a name, age, and gpa. For input use fgets for the name and scanf for the age and gpa. The values should be stored in the structure pointed to by per.
Write a second function with the following signature:
void show_person(struct Person* per)
This function should use printf to print out each of the members of the structure pointed to by per.
Your main function needs only three lines:
- Create a struct person object
- Call the fill_person function
- Call the show_person function
I've started my code but I can not get it to compile, can any one help?
Here's my code:
Code:1 #include<stdio.h>Code:2 struct Person 3 { 4 char name[100]; 5 int age; 6 float gpa; 7 8 }; 9 void fill_person(struct Person* per) 10 { 11 printf("Enter name of student:"); 12 fgets("%c",100, per->name); 13 printf("Enter age of student:"); 14 scanf("%d", per->age); 15 printf("Enter GPA of student:"); 16 scanf("%f", per->gpa); 17 18 } 19 void show_person(struct Person* per) 20 { 21 fgets("%c",100, per->name); 22 printf("%d", per->age); 23 printf("%f", per->gpa); 24 } 25 26 27 28 int main() 29 { 30 }
here is the error I'm recieving:
Code:assignment12.c: In function 'fill_person':Code:assignment12.c:12: warning: passing argument 3 of 'fgets' from incompatible pointer type /usr/include/stdio.h:604: note: expected 'struct FILE * __restrict__' but argument is of type 'char *' assignment12.c: In function 'show_person': assignment12.c:21: warning: passing argument 3 of 'fgets' from incompatible pointer type /usr/include/stdio.h:604: note: expected 'struct FILE * __restrict__' but argument is of type 'char *'



LinkBack URL
About LinkBacks




I used to be an adventurer like you... then I took an arrow to the knee.