Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Matt Cain
- COP 3223
- Dr. Laviola
- Assignment #3 */
- #include <stdlib.h>
- #include <stdio.h>
- FILE *file;
- int num_schedules;
- int i, j, k;
- int num_entries;
- int main(void) {
- file = fopen("schedule.txt", "r");
- fscanf(file, "%d", &num_schedules);
- printf("This is the number of schedules: %d\n",num_schedules);
- for (i=0; i<num_schedules; i++) { //For each schedule...
- int scheduled_hours[168];//Initialize array
- for (j=0; j<168; j++){
- scheduled_hours[j] = 0;
- }
- fscanf(file, "%d", &num_entries);
- for (j=0; j<num_entries; j++) { //For each entry
- int day, start, end;
- fscanf(file, "%d", &day);
- fscanf(file, "%d", &start);
- fscanf(file, "%d", &end);
- int conflict = 0;
- for (k=day*24+start; k<day*24+end; k++) {
- if (scheduled_hours[k]==1)
- conflict=1;
- }
- if (!conflict) {
- for (k=day*24+start; k<day*24+end; k++) {
- scheduled_hours[k] += 1;
- }
- }
- }
- int total_hours = 0;
- for (j=0; j<168; j++) {
- if (scheduled_hours[j] == 1) //If 1 is found within the array, the total hours is incremented by 1
- total_hours++;
- }
- printf("Schedule %d contains %d hours of scheduled activity.\n", i+1, total_hours);
- }
- fclose(file);
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment