I have read about 5 different questions on the same error, but I still can’t find what’s the problem with my code.
main.c
int main(int argc, char** argv) {
//graph_t * g = graph_create(128); //I commented this line out to make sure graph_create was not causing this.
graph_t * g;
g->cap; //This line gives that error.
return 1;
}
.c
struct graph {
int cap;
int size;
};
.h
typedef struct graph graph_t;
Thanks!
You can’t do that since the struct is defined in a different source file. The whole point of the typedef is to hide the data from you. There are probably functions such as
graph_capandgraph_sizethat you can call that will return the data for you.If this is your code, you should define
struct graphinside the header file so all files that that include this header will be able to have the definition of it.