Guest User

Untitled

a guest
Jan 23rd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 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.  
  36. int conflict = 0;
  37.  
  38. for (k=day*24+start; k<day*24+end; k++) {
  39. if (scheduled_hours[k]==1)
  40. conflict=1;
  41. }
  42. if (!conflict) {
  43. for (k=day*24+start; k<day*24+end; k++) {
  44. scheduled_hours[k] += 1;
  45. }
  46.  
  47. }
  48. }
  49.  
  50.  
  51. int total_hours = 0;
  52. for (j=0; j<168; j++) {
  53. if (scheduled_hours[j] == 1) //If 1 is found within the array, the total hours is incremented by 1
  54. total_hours++;
  55. }
  56.  
  57. printf("Schedule %d contains %d hours of scheduled activity.\n", i+1, total_hours);
  58. }
  59.  
  60. fclose(file);
  61.  
  62. system("PAUSE");
  63. return 0;
  64.  
  65. }
Add Comment
Please, Sign In to add comment