c - Program runs then says it has stopped working. Debugging issues -
i writing code in c using codeblocks take schedule , tells if double booked on item.
the file setup like:
2 2 0 1 5 1 8 12
where 1st number how many schedules there , second number how many scheduled items in schedule.
the next few lines read 0
sunday, 1
monday , forth , hours day schedule full, start time end time.
my code is:
//10/14/11 //this code functions let user know if schedule conflicts exist in amount of schedules. #include <stdio.h> int main() { int hours_week[168]; int num_schedules; int num_items; int i; int j; int k; int w; file* ifp; int day; int start; int end; int schedule; int booked; int index; //initialize array setting each spot equal zero. (w=0; w<168; w++){ hours_week[w] = 0; } //read in file schedule.txt ifp = fopen("schedule.txt","r"); //read in number of schedules fscanf(ifp, "%d", &num_schedules); //create loop run many times there schedules. (i=0; i<num_schedules; i++){ //read in number of items in schedule. fscanf(ifp, "%d", &num_items); j = 0; while (j < num_items){ j++; //read in day, start time, , end time. fscanf(ifp, "%d", day); fscanf(ifp, "%d", start); fscanf(ifp, "%d", end); //multiply day 24 , add start , end hours new times. start = (day * 24) + start; end = (day * 24) + end; (k = start; k <= end; k++){ if (hours_week[k] == 0) hours_week[k] = 1; else if (hours_week[k] == 1) schedule = booked; } //close file fclose(ifp); if (schedule == booked) printf("i'm sorry, schedule %d has conflict in it.\n", i); else printf("great planning! have no schedule conflicts in schedule %d.\n", i); } } return 0; }
you miss address-of operator here
//read in day, start time, , end time. fscanf(ifp, "%d", day); fscanf(ifp, "%d", start); fscanf(ifp, "%d", end);
correct should be
//read in day, start time, , end time. fscanf(ifp, "%d", &day); fscanf(ifp, "%d", &start); fscanf(ifp, "%d", &end);
it's strange it's correct above! time go sleep, me @ least!
Comments
Post a Comment