Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

structure identifier is not defined even though it is

I have a school project where I have to make my structures and functions in a .h header file.

I’ve created my structure but cannot use any of the variables within it as whenever I call it it highlights the structure name and tells me its not defined even though it clearly is in my structure and doesn’t highlight or give me any syntax errors.

#include <stdio.h>

typedef struct test1 {
    int array1[3];
    int array2[3];
};

int main(void) {
    scanf_s(" %d %d", &test1.array1[1], &test1.array2[1]);

}

I have tried using typedef with and without and its the same result. if I create individual variables outside the structure I get no issues so i believe its some issue with how I’m creating my structures but I don’t know what the issue is.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The use of typedef makes me think that you actually want to define a type named test1. Move the name to after the struct:

#include <stdio.h>

typedef struct {
    int array1[3];
    int array2[3];
} test1;            // now a name you can use

You then need to create an instance of test1 to be able to use it with scanf_s:

int main(void) {
    test1 t1;      // `t1` is now a `test1` instance

    scanf_s(" %d %d", &t1.array1[1], &t1.array2[1]);
//                     ^^             ^^
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading