In c language for this question need pointer however i cant understand how can i link with course and student struct with pointer.program expected AddCourse operation and take course id and student id and again loop addcourse again again if i write exit, stop loop and print students taken course and struct info. this is the question:
structures must be filled by user inputs. After filling your structures, you will let user to get any student enroll to any course from the course list. Hint: To achieve these steps, you must use pointer in your student structure to link it to course structure"
i add photos for the expected program output please open this two images and two images are dependented.
and its my incomplete code because how can i use to link two struct with pointer.
#include <string.h>
#include <stdio.h>
struct student
{
char name[50],surname[50];
int id,year;
};
struct Courses{
char course_name[50];
int course_id,course_credit;
};
int main(){
struct student std[2];
struct Courses crs[4];
printf("enter information of students:\n");
for(int i=0; i<2;i++){
printf("Enter student id:");
scanf("%d",&std[i].id);
printf("Enter first name:");
scanf("%s",std[i].name);
printf("Enter last name:");
scanf("%s",std[i].surname);
printf("Enter year:");
scanf("%d",&std[i].year);
printf("\n");
}
printf("Enter information of courses:\n");
for (int i = 0; i < 4; i++)
{
printf("course id:");
scanf("%d",&crs[i].course_id);
printf("course name:");
scanf("%s",&crs[i].course_name);
printf("course credit:");
scanf("%d",&crs[i].course_credit);
printf("\n");
}
printf("-Displaying Courses-\n");
for(int i=0; i<4;i++){
printf("course id:%d\n",crs[i].course_id);
printf("course name :%s\n",crs[i].course_name);
printf("course credit:%d",crs[i].course_credit);
printf("\n");
}
printf("-Display Students-\n");
for(int i=0; i<2;i++){
printf("student id:%d\n",std[i].id);
printf("student name and surname:%s %s\n",std[i].name,std[i].surname);
printf("year:%d",std[i].year);
printf("\n");
}
return 0;
}