Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Assignment: 5
- Campus: Ashdod
- Author: Matan Tal, ID: 201492881
- */
- #define _CRT_SECURE_NO_WARNINGS
- #define SIZE 20
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- struct date
- {
- int day, month, year;
- };
- struct lecturer
- {
- char *name;
- struct date birthdate;
- int num_of_courses;
- char **courses;
- };
- void createlecture(struct lecturer *lectu);
- int main(void)
- {
- int amount, i;
- struct lecturer *lect=NULL;
- printf("How many lecturs do you want to specifiy?\n");
- scanf("%d", &amount);
- lect = (struct lecturer*)malloc(amount*sizeof(struct lecturer));\
- if(!lect)
- {
- printf("ERROR! Out of memory!\n");
- exit(1);
- }
- for(i=0; i<amount; i++)
- {
- printf("Enter the %d\n", i+1);
- createlecture(&lect[i]);
- }
- free(lect);
- }
- void createlecture(struct lecturer *lectu)
- {
- int i;
- lectu->name = malloc(SIZE*sizeof(char));
- if(lectu->name ==NULL)
- {
- printf("ERROR! Out of memory!\n");
- free(lectu);
- exit(1);
- }
- printf("Enter the birthday starting -day-\n");
- scanf("%d", &(lectu->birthdate.day));
- printf("Enter the birthdaystarting -month-\n");
- scanf("%d", &(lectu->birthdate.month));
- printf("Enter the birthday starting -year-\n");
- scanf("%d", &(lectu->birthdate.year));
- printf("how many courses for the lecture?\n");
- scanf("%d", &(lectu->num_of_courses));
- lectu->courses = (char**)malloc(lectu->num_of_courses*sizeof(char*));
- if(!lectu->courses)
- {
- printf("ERROR! Out of memory!\n");
- free(lectu->name);
- free(lectu);
- exit(1);
- }
- for(i=0; i<lectu->num_of_courses; i++)
- {
- lectu->courses[i] = (char*)malloc(SIZE*sizeof(char));
- if(!lectu->courses)
- {
- printf("ERROR! Out of memory!\n");
- free(lectu->name);
- free(lectu->courses);
- free(lectu);
- exit(1);
- }
- }
- for(i=0; i<(lectu->num_of_courses); i++)
- {
- printf("What the name of courses? start with the %d:\n", i+1);
- scanf("%s", (lectu->courses[i]));
- }
- }
- void coursesLectures(struct lecturer *lectu int teachers)
- {
- int i, j;
- char coursName[SIZE]=NULL;
- printf("Enter name course for serching the lecture teaching\n");
- scanf("%s",coursName);
- for(i=0; i<teachers; i++)
- {
- for(j=0; j<sizeof(*lectu[i]->courses); j++)
- {
- if(strcmp(lectu[i]->courses[j],coursName)==0)
- printf("%s", lectu[i]->name);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement