Please help me with this C question. Please do not change it drastically and jus
ID: 3728861 • Letter: P
Question
Please help me with this C question. Please do not change it drastically and just add things to the existing functions in the schedule.c file and do not change any variable names. Also, please make sure to follow the instructions.
INSTRUCTIONS:
HEADER FILE (you can add things if necessary, but please do not delete or change anything already there):
.C FILE (Please fill out the functions already listed and DO NOT change any variable names or anything already existing/already written ):
MAIN (just for testing if needed):
schedule·c schedule,h Evaluation: (8 marks) . Reading the events from a binary file (4 marks) Printing the schedule from the events (4 marks)Explanation / Answer
here is your program : -------------->>>>>>>>>>>>>
#include "schedule.h"
void createBinaryFile(char *filename){
int i;
FILE *ptr = fopen(filename,"wb");
char names[][64] = {"breakfast","commute","meeting","lunch","seminar","gym","commute","dinner"};
int starts[] = {8,8,10,12,13,16,18,19};
boolean halfHours[] = {false,true,false,false,false,true,false,false};
int durations[] = {30,45,75,60,180,80,45,30};
for(i = 0;i<8;i++){
Event n;
sprintf(n.name,"%s",names[i]);
n.startTime = starts[i];
n.halfHour = halfHours[i];
n.duration = durations[i];
fwrite(&n,sizeof(Event),1,ptr);
}
fclose(ptr);
}
void printSchedule(Event *list,int listlength){
int i = 0;
int j = 8;
int k = 0;
for(j;j<22;){
if(j >= 12){
int t = j -12;
printf(" %02d:%02d",t,k);
printf(" pm - ");
}else if(j < 12){
printf(" %02d:%02d",j,k);
printf(" am - ");
}
if(list[i].startTime == j){
if(k == 30){
if(list[i].halfHour == true){
printf("%s",list[i].name);
i++;
}
}else{
if(list[i].halfHour == false){
printf("%s",list[i].name);
i++;
}
}
}
if(k == 0){
k = 30;
}else{
k = 0;
j++;
}
}
}
int readBinaryFile(char *filename,Event **list){
*list = (Event *)malloc(sizeof(Event)*22);
int listlength = 0;
FILE *ptr = fopen(filename,"rb");
if(ptr == NULL){
return 0;
}
for(listlength;listlength < 22;listlength++){
if(fread(&((*list)[listlength]),sizeof(Event),1,ptr)){
}else{
break;
}
}
fclose(ptr);
return listlength-1;
}
int main(){
char *filename = "data123.txt";
createBinaryFile(filename);
Event *list;
int listlength = 0;
listlength = readBinaryFile(filename,&list);
printSchedule(list,listlength);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.