Hello everyone, I am experiencing a warning of dereferencing a pointer in my sortFunction. It is occuring on line 4 of the sortFunction. The compiler is also telling me "request for member 'course' in something not a structure or union" when clearly it is. It is also on the same line.
I am using qsort on a typedef struct and not seeming to get where mmy problem is. I am hoping someone can tell me what I can do to fix it. I have included my .h , main and sortFunction files. They are not long.
classes.h:
Code:
#define CLASSES_H_INCLUDED
#include <stdio.h>
#include <stdlib.h>
#define BINFILE "classes.db"
#define MAX_RECORD 10
typedef enum {MW, TR} days;
typedef struct {
int hour, min;
} Time;
typedef struct {
char Dept[5];
int course, sect;
days meet_days;
Time start, end;
char instr[20];
} sched_record;
int sortFunction(const void *p, const void *q);
#endif // CLASSES_H_INCLUDED
main.c
Code:
#include "classes.h"
int main(void)
{
int switchInput;
int i,temp;
char cName[10];
FILE *filePointer;
sched_record data[MAX_RECORD];
filePointer = fopen (BINFILE, "rb");
if (filePointer == NULL) {
printf("**Can't open file**");
printf("**Check file permissions of file path**");
exit(1);
}
printf("Enter your choice: ");
scanf("%d", &switchInput);
switch(switchInput)
{
case 1:
fread(data, sizeof(sched_record), MAX_RECORD, filePointer);
fclose(filePointer);
qsort(data, MAX_RECORD, sizeof(sched_record), sortFunction);
for (i = 0; i < MAX_RECORD; i++ ){
printf("\n%s", data[i].course);
}
}
}
sortFunction:
Code:
#include "classes.h"
int sortFunction(const void *p, const void *q) {
return ((sched_record *) p)->course - ((sched_record *) q->course);
}