Declared structures:
typedef struct{
char fname[25];
char mname[3];
char lname[25];
}Name;
typedef struct{
char month[25];
int day,year;
}Date;
typedef struct{
Name gname;
char addr[50];
char cnum[11];
}Guardian;
typedef struct{
Name sname;
Date sbday;
Guardian sguard;
char gender[6];
char addr[50];
char cnum[11];
char course[10];
int year;
}Student;
Declared functions:
void input(Name name,Date date, Guardian guard, Student stud);
void display(Name name,Date date, Guardian guard, Student stud);
When input function is called, it lets me add strings being asked. Then, display function is called. It will not display the entered information.
Calling functions:
input(name, date, guard, stud);
display(name, date, guard, stud);
Display funtion:
void display(Name name, Date date, Guardian guard, Student stud)
{
printf(" -=Student Information=- \n");
printf("Name: %s %s. %s\n",stud.sname.fname,stud.sname.mname,stud.sname.lname);
printf("Birtday: %s %d, %d\n",stud.sbday.month,stud.sbday.day,stud.sbday.year);
printf("Gender: %s\n",stud.gender);
printf("Contact Number: \n%s",stud.cnum);
printf("Course & Year: %s-%d \n",stud.course,stud.year);
printf(" -=Student Guardian Information=- \n");
printf("Name: %s %s. %s\n",guard.gname.fname,guard.gname.mname,guard.gname.lname);
printf("Address: %s\n",guard.addr);
printf("Contact Number: %s\n",guard.cnum);
}
Input function:
void input(Name name,Date date, Guardian guard, Student stud)
{
printf("Student Information \n");
printf("First Name: ");
gets(stud.sname.fname);
//...
}
This will just display one set of information. It won't add new records per say. Just a simple exercise.
char*and dynamically allocate. Some of these buffers are ridiculously short.gets. It's a dangerous function which have been removed from the C specification. Use alternatives likefgetsinstead.