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