Guest User

Untitled

a guest
Jan 23rd, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. /* Matt Cain
  2. COP 3223
  3. Dr. Laviola
  4. Assignment #3 */
  5.  
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. FILE *file;
  9.  
  10. int num_schedules;
  11. int i, j, k;
  12.  
  13. int num_entries;
  14.  
  15. int main(void) {
  16. file = fopen("schedule.txt", "r");
  17. fscanf(file, "%d", &num_schedules);
  18. printf("This is the number of schedules: %d\n",num_schedules);
  19.  
  20.  
  21. for (i=0; i<num_schedules; i++) { //For each schedule...
  22.  
  23. int scheduled_hours[168];//Initialize array
  24. for (j=0; j<168; j++){
  25. scheduled_hours[j] = 0;
  26. }
  27.  
  28. fscanf(file, "%d", &num_entries);
  29.  
  30. for (j=0; j<num_entries; j++) { //For each entry
  31. int day, start, end;
  32. fscanf(file, "%d", &day);
  33. fscanf(file, "%d", &start);
  34. fscanf(file, "%d", &end);
  35. for (k=day*24+start; k<day*24+end; k++) {
  36. scheduled_hours[k] += 1;
  37. }
  38. }
  39.  
  40. int error = 0;
  41. for (j=0; j<168; j++) {
  42. if (scheduled_hours[j] > 1)
  43. error = 1;
  44. }
  45.  
  46. if (error) {
  47. printf("Schedule #%d: Sorry, you double booked yourself again.\n", i+1);
  48. } else {
  49. printf("Schedule #%d: Good job, no conflicts!\n", i+1);
  50. }
  51.  
  52. }
  53.  
  54. fclose(file);
  55.  
  56. system("PAUSE");
  57. return 0;
  58. }
Add Comment
Please, Sign In to add comment