Advertisement
Guest User

Untitled

a guest
Jan 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. /* Assignment: 5
  2. Campus: Ashdod
  3. Author: Matan Tal, ID: 201492881
  4. */
  5. #define _CRT_SECURE_NO_WARNINGS
  6. #define SIZE 20
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. struct date
  11. {
  12. int day, month, year;
  13. };
  14. struct lecturer
  15. {
  16. char *name;
  17. struct date birthdate;
  18. int num_of_courses;
  19. char **courses;
  20.  
  21. };
  22. void createlecture(struct lecturer *lectu);
  23.  
  24. int main(void)
  25. {
  26. int amount, i;
  27. struct lecturer *lect=NULL;
  28. printf("How many lecturs do you want to specifiy?\n");
  29. scanf("%d", &amount);
  30. lect = (struct lecturer*)malloc(amount*sizeof(struct lecturer));\
  31. if(!lect)
  32. {
  33. printf("ERROR! Out of memory!\n");
  34. exit(1);
  35. }
  36. for(i=0; i<amount; i++)
  37. {
  38. printf("Enter the %d\n", i+1);
  39. createlecture(&lect[i]);
  40. }
  41. free(lect);
  42.  
  43. }
  44. void createlecture(struct lecturer *lectu)
  45. {
  46. int i;
  47.  
  48. lectu->name = malloc(SIZE*sizeof(char));
  49. if(lectu->name ==NULL)
  50. {
  51. printf("ERROR! Out of memory!\n");
  52. free(lectu);
  53. exit(1);
  54. }
  55. printf("Enter the birthday starting -day-\n");
  56. scanf("%d", &(lectu->birthdate.day));
  57. printf("Enter the birthdaystarting -month-\n");
  58. scanf("%d", &(lectu->birthdate.month));
  59. printf("Enter the birthday starting -year-\n");
  60. scanf("%d", &(lectu->birthdate.year));
  61. printf("how many courses for the lecture?\n");
  62. scanf("%d", &(lectu->num_of_courses));
  63. lectu->courses = (char**)malloc(lectu->num_of_courses*sizeof(char*));
  64. if(!lectu->courses)
  65. {
  66. printf("ERROR! Out of memory!\n");
  67. free(lectu->name);
  68. free(lectu);
  69. exit(1);
  70. }
  71. for(i=0; i<lectu->num_of_courses; i++)
  72. {
  73. lectu->courses[i] = (char*)malloc(SIZE*sizeof(char));
  74. if(!lectu->courses)
  75. {
  76. printf("ERROR! Out of memory!\n");
  77. free(lectu->name);
  78. free(lectu->courses);
  79. free(lectu);
  80. exit(1);
  81. }
  82. }
  83. for(i=0; i<(lectu->num_of_courses); i++)
  84. {
  85. printf("What the name of courses? start with the %d:\n", i+1);
  86. scanf("%s", (lectu->courses[i]));
  87. }
  88.  
  89. }
  90. void coursesLectures(struct lecturer *lectu int teachers)
  91. {
  92. int i, j;
  93. char coursName[SIZE]=NULL;
  94. printf("Enter name course for serching the lecture teaching\n");
  95. scanf("%s",coursName);
  96. for(i=0; i<teachers; i++)
  97. {
  98. for(j=0; j<sizeof(*lectu[i]->courses); j++)
  99. {
  100. if(strcmp(lectu[i]->courses[j],coursName)==0)
  101. printf("%s", lectu[i]->name);
  102. }
  103. }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement