Hello, I'm writing a program that allows an user to enter student information, and then will hold the information and will allow the user to "delete a student", "add a student", show class (which shows all the students entered by user). I've been working on this code for a while and I'm still working out some last minute errors, if anyone could help me with this it would be greatly appreciated.... Here's the code I have:
Code:
#include <stdio.h>
struct Person
{
char name[100];
int age;
float gpa;
};
void fill_person(struct Person* per)
{
printf("Enter name of student:");
fgets(per->name,100,stdin);
printf("Enter age of student:");
scanf("%d", &per->age);
printf("Enter GPA of student:");
scanf("%f", &per->gpa);
}
void show_person(struct Person* per)
{
printf("name:%s\n", per->name);
printf("age:%d\n", per->age);
printf("GPA:%f\n", per->gpa);
}
struct Classroom
{
int num_students;
struct Person student[100];
};
void add_a_person(struct Classroom* crp)
{
for(crp.num_students=0;num_students<100;++num_students)
{
crp->num_students.fill_person=num_students+1;
struct Person student;
fill_person(&student);
}
}
void delete_a_person(struct Classroom* crp)
{
char search_name[100];
printf("what is the name of the student you would like to delete?\n");
fgets(search_name, 100, stdin);
int i;
while (i=0; i<crp->num_students && strcmp(crp->student[i], search_name)!=0)
i++;
while (strcmp(search_name,crp->student[i].name)!=0 && i<crp->num_students)
i++;
if(i==crp->num_students)
{
printf("No match\n");
}
}
void show_class(struct Classroom* crp)
{
while(0<crp->num_students)
{
show_person(crp->student);
}
}
int main()
{
struct Classroom crp;
crp.num_students=0;
while(crp->num_students<100)
{
printf("1. Add a student\n");
scanf("%d", crp->add_a_person);
printf("2. Show class\n");
scanf("%d", crp->show_class);
printf("3. Delete a student\n");
scanf("%d", crp->delete_a_person);
printf("4. Exit\n");
}
}
83,1 Bot
This is the error I'm recieving:
Code:
project_test.c: In function 'add_a_person':
project_test.c:36: error: request for member 'num_students' in something not a structure or union
project_test.c:36: error: 'num_students' undeclared (first use in this function)
project_test.c:36: error: (Each undeclared identifier is reported only once
project_test.c:36: error: for each function it appears in.)
project_test.c:38: error: request for member 'fill_person' in something not a structure or union
project_test.c: In function 'delete_a_person':
project_test.c:49: error: expected ')' before ';' token
project_test.c: In function 'main':
project_test.c:71: error: invalid type argument of '->' (have 'struct Classroom')
project_test.c:74: error: invalid type argument of '->' (have 'struct Classroom')
project_test.c:76: error: invalid type argument of '->' (have 'struct Classroom')
project_test.c:78: error: invalid type argument of '->' (have 'struct Classroom')
This is one of my first times using c, I usually use C++.I'm not sure how to set a way for when the user enters 4 to get the program to end, also, I'm not sure if my delete a person function and my add a person function are completley correct too...Any help with this program is much needed, thank you!