#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    142
    Rep Power
    2

    Compiler not recognizing array


    Code:
    #include <stdio.h>
    #define STRIZ 30
    #define NUM_T 3
    #define NUM_Q 2
    #define NUM_C 20
    typedef struct
    {
        int id;
        char name[STRIZ];
        char sex;
        int score[NUM_T][NUM_Q];
        int mid[NUM_T];
        int fin[NUM_T];
        int total;
    } rec_t;
    int get(rec_t *ptr);
    int main()
    {
        rec_t rec[NUM_C];
        get(&rec[0]);
    }
    int get(rec_t *ptr)
    {
        int status = 0, i, j;
    
    //    printf("enter ID> ");
    //    status += scanf("%d", &ptr->id);
    //    printf("input: %d\n", ptr->id);
    //
    //    printf("enter name> ");
    //    status += scanf("%s", ptr->name);
    //    printf("input: %s\n", ptr->name);
    //
    //    printf("enter sex> ");
    //    status += scanf(" %c", &ptr->sex);
    //    printf("input: %c\n", ptr->sex);
    
    //    for(i = 0; i < NUM_T; ++i)
    //    {
    //        printf("score for semester #%d\n", i + 1);
    //        for(j = 0; j < NUM_Q; ++j)
    //        {
    //            printf("  quiz #%d> ", j + 1);
    //            scanf("%d", &ptr->score[i][j]);
    //            printf("(%d, %d) = %d\n", i, j, ptr->score[i][j]);
    //        }
    //
    //    }
    
        for(i = 0; i < NUM_T; ++i)
        {
            printf("enter midterm score for semester #%d\n", i + 1);
            scanf("%d", &ptr->mid[i]);
            printf("midterm (%d) = %d\n", i + 1, mid[i]);
    
    
        }
        printf("status = %d\n", status);
    
    }
    in line 54, the compiler tells me mid is undeclared.
    but clearly I HAVE declared mid as an array in the structure declaration.
    what's wrong?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2009
    Posts
    45
    Rep Power
    8
    Code:
    ptr->mid[i]
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    142
    Rep Power
    2
    Turns out I've been looking at the wrong line....
    Thanks for the help.

IMN logo majestic logo threadwatch logo seochat tools logo