I keep getting this error whenever I stop my program and I am wondering am I freeing memory right.
This is my structure and I created a global array named day.
typedef struct {
int hour;
int minute;
} Time;
typedef struct {
Time startTime;
Time endTime;
char subject[20];
char location[20];
} Appointment;
typedef struct {
int day;
int month;
Appointment *appts[8];
int apptCount;
} Day;
Day *day = NULL;
At the end of my main()
for (i = 0; i < daysize; ++i) {
for (j = 0; j < day[i].apptCount; ++j) {
free(day[i].appts[j]->location);
free(day[i].appts[j]->subject);
} // for j
} // for i
free(day);
daysize is a global variable that keeps track of the number of elements in the array. I also have a variable called allocate that keeps track of how much memory, that I have given to my array day. I don't think I will need that number because free(day) should also free unused memories in it.
I also have a question about the fgets() function. Does it prompt the user to input in a stream of data? I tried to input the code fgets(string, 100, stdin); into my program and whenever my program runs, it does not prompt me to type something. I had to put getchar() before the fgets. I am wondering am I supposed to do that?