Is there a way to evaluate an enum? I have an enum that is incorporated into a struct:
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;
My print statement for the enum is:
data[i].meet_days == MW ? "MW" : "TR"
What I am trying to do is to get my typedef struct of sched_record to print only the records with say MW in it. My “menu” for the program is as follows:
fread(data, sizeof(sched_record), MAX_RECORD, filePointer);
fclose(filePointer);
printf("Enter the Department or A for any Department: ");
scanf("%s", tempDept);
printf("Enter the Course or 0 for any course: ");
scanf("%d", &tempCourse);
printf("Enter the Days; M = MW, T = TTH or D=Don't Care: ");
scanf("%s", tempDay);
printf("Enter the Time; A=Mornings, P=Afternoons or D=Don't Care: ");
scanf("%s", tempTime);
I got my sched_records to print out by time with a simple statement of:
else if ((strcmp(tempDept, "A")==0) && tempCourse == 0 && (strcmp(tempDay, "D")==0) && (strcmp(tempTime, "P")==0)) {
if (data[i].start.hour >= 12) { // <---Time comparison
printf("%s %d %d %2s %02d%02d %02d%02d %s\n", data[i].Dept, data[i].course, data[i].sect, data[i].meet_days == MW ? "MW" : "TR",
data[i].start.hour, data[i].start.min, data[i].end.hour, data[i].end.min, data[i].instr);
}
}
else if ((strcmp(tempDept, "A")==0) && tempCourse == 0 && (strcmp(tempDay, "M")==0) && (strcmp(tempTime, "D")==0)) {
printf("\n%s %d", data[i].Dept, data[i].course);
I am wondering if there is a simple way like the time comparison to do the same with the enum. If so can someone show me?
You can compare enumerated values in the same way as any other integer variable:
Or, if say you had an enumeration for all days:
then you can test ranges like this:
Hope that helps.