Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #defin#define _CRT_SECURE_NO_WARNINGS
- #define N 20
- #include<stdio.h>
- #include<string.h>
- #include<stdlib.h>
- struct date
- {
- int day, month, year;
- };
- struct lecturer
- {
- char *name;
- struct date birthday;
- int num_of_courses;
- char **courses;
- };
- void Course_Lectures(struct lecturer *arr1, char name[N], int size)
- {
- int i, j;
- int i_course, j_course;
- for (i = 0; i < size; i++)
- {
- for (j = 0; j < arr1[i].num_of_courses; j++)
- {
- if (strcmp(name, arr1[i].courses[j]) == 0)
- {
- puts(arr1[i].name);
- }
- }
- }
- }
- void common(struct lecturer *arr1, char name1[N], char name2[N], int size)
- {
- int i, j;
- int i_name, j_name;
- for (i = 0; i < size; i++)
- {
- if (strcmp(name1, arr1[i].name) == 0)
- {
- i_name = i;
- }
- if (strcmp(name2, arr1[i].name) == 0)
- {
- j_name = i;
- }
- }
- for (i = 0; i < arr1[i_name].num_of_courses; i++)
- {
- for (j = 0; j < arr1[j_name].num_of_courses; j++)
- if ((strcmp(arr1[i_name].courses[i], arr1[j_name].courses[j])) == 0)
- printf(arr1[i_name].courses[i]);
- }
- }
- void old(struct date old, struct lecturer *arr1, int size)
- {
- int i, j;
- for (i = 0; i < size; i++)
- {
- if (arr1[i].birthday.year < old.year)
- {
- puts(arr1[i].name);
- }
- else if (arr1[i].birthday.year = old.year)
- {
- if (arr1[i].birthday.month < old.month)
- {
- if (arr1[i].birthday.day <= old.day)
- {
- puts(arr1[i].name);
- }
- }
- }
- }
- }
- int main()
- {
- struct lecturer *lecturers = NULL;
- int size, i, j;
- struct date old1;
- char name[N], name1[N], name2[N], NameCourse[N];
- printf("enter please the number of the lectrures :\n ");
- scanf("%d", &size);
- lecturers = (struct lecturer*)malloc(size * sizeof(struct lecturer));
- if (lecturers == NULL)
- {
- printf("error \n");
- return 0;
- }
- for (i = 0; i < size; i++)
- {
- printf("enter the name of the prof:\n");
- scanf("%s", name);
- lecturers[i].name = (char*)malloc((strlen(name) + 1) * sizeof(char));
- if (lecturers[i].name == NULL)
- {
- printf("memory error \n");
- // Oh look memory leak. Free your things!
- return 0;
- }
- for (j = 0; j < strlen(name); j++)
- {
- lecturers[i].name[j] = name[j];
- }
- lecturers[i].name[j] = '\0';
- printf("please enter the birthday of the prof :\n");
- scanf("%d%d%d", &lecturers[i].birthday.day, &lecturers[i].birthday.month, &lecturers[i].birthday.year);
- printf("enter the number of courses of the prof :\n");
- scanf("%d", &lecturers[i].num_of_courses);
- lecturers[i].courses = (char**)malloc(lecturers[i].num_of_courses * sizeof(char*));
- for (j = 0; j<lecturers[i].num_of_courses; j++)
- {
- lecturers[i].courses[j] = (char*)malloc(N * sizeof(char));
- if (lecturers[i].courses[j] == NULL)
- {
- printf("memory error \n");
- // Oh look memory leak. Free your things!
- return 0;
- }
- printf("enter the name of the course :\n");
- scanf("%s", lecturers[i].courses[j]);
- }
- }
- printf("enter the name of the course :\n");
- scanf("%s", NameCourse);
- Course_Lectures(lecturers, name, size);
- printf("enter names of two profs\n");
- scanf("%s", name1);
- scanf("%s", name2);
- common(lecturers, name1, name2, size);
- printf("enter the date after which the prof was born");
- scanf("%d%d%d", &old1.day, &old1.month, &old1.year);
- old(old1, lecturers, size);
- free(lecturers);
- for (i = 0; i < size; i++)
- {
- for (j = 0; j<lecturers[i].num_of_courses; j++)
- free(lecturers[i].courses[j]);
- }
- for (i = 0; i < size; i++)
- free(lecturers[i].courses);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement