Thread: using comparative operator on a typedef struct member

  1. #1
    Registered User
    Join Date
    Jul 2010
    Posts
    178

    using comparative operator on a typedef struct member

    I have tried:
    Code:
     if (data[i].start.hour >= "1200")
    and obviously it does not work for I get an error of:
    Code:
    comparison between pointer and integer
    Is there a way to do a statement with this same process in mind? I am trying to print out a schedule for the classes the meet after 12 noon. If so, how would it be done? I have included I believe the necessary code.
    structs:
    Code:
    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;
    And here is my relevant code in its for loop:
    Code:
     fread(data, sizeof(sched_record), MAX_RECORD, filePointer);
                fclose(filePointer);
                printf("Enter the 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);
    
                    for (i=0; i < MAX_RECORD; i++) {
                        if (tempCourse == 0 && (strcmp(tempDay, "D")==0) && (strcmp(tempTime, "D")==0)) {
    
                             if (strcmp(tempDept, data[i].Dept)==0) {
                                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 (tempCourse == 0 && (strcmp(tempDay, "D")==0) && (strcmp(tempTime, "A")==0)) {
    
                             if (strcmp(tempDept, data[i].Dept)==0) {
                                    if (data[i].start.hour >= "1200"){  // <-- THIS LINE
                                     printf("\n%s %d", data[i].Dept, data[i].course);
                                    }
                             }
                        }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    "1200" isn't an integer. It's a string literal. Lose the quotes if you want the number 1200, and just put 1200.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Jul 2010
    Posts
    178
    Quote Originally Posted by quzah View Post
    "1200" isn't an integer. It's a string literal. Lose the quotes if you want the number 1200, and just put 1200.


    Quzah.
    Sweet! Thanks! Actually I needed just 12. I realized right after I posted that the start.hour is 12. start.min is 00.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assign struct member value to struct member value
    By thahemp in forum C Programming
    Replies: 5
    Last Post: 10-13-2010, 09:48 AM
  2. differences between struct and typedef struct
    By stanlvw in forum C Programming
    Replies: 1
    Last Post: 07-22-2008, 03:28 PM
  3. Member Function Pointers - Typedef vs. Not
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 12-15-2006, 07:30 AM
  4. Pointer to member typedef
    By laserlight in forum C++ Programming
    Replies: 4
    Last Post: 03-04-2006, 10:04 AM
  5. Diff btw typedef struct and struct?
    By willkoh in forum C Programming
    Replies: 3
    Last Post: 09-24-2005, 02:27 PM