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);
- for (k=day*24+start; k<day*24+end; k++) {
- scheduled_hours[k] += 1;
- }
- }
- int error = 0;
- for (j=0; j<168; j++) {
- if (scheduled_hours[j] > 1)
- error = 1;
- }
- if (error) {
- printf("Schedule #%d: Sorry, you double booked yourself again.\n", i+1);
- } else {
- printf("Schedule #%d: Good job, no conflicts!\n", i+1);
- }
- }
- fclose(file);
- system("PAUSE");
- return 0;
- }
Add Comment
Please, Sign In to add comment