Not any homework, but seem to have got lost while doing basics, hence asking.
Say I have 2 C source files. 1.c & 2.c
2.c is as follows:
typedef struct mystr_
{
int a;
float b;
}mystr;
void fun()
{
mystr q;
some code....
}
And 1.c is as below:
#include "stdio.h"
void fun();
main()
{
//How to access / declare a variable of type mystr here.
mystr *v1;//This obviously gives compiler errors
some code....
}
How to access the structure mystr defined in 2.c from file 1.c to have variables of that struct type there?
EDIT:
Sorry forgot to mention in OP. I cannot move the declaration out in a header file for some reason –> It is a quick hack that I am trying to check in a existing code. Then is there any way to access it directly from the other source file?
Use headers.
Create a file
2.hAnd include it in
1.cEDIT:
Because you are not able to extract the declaration into a header file and include it, there is no other way than copying the declaration. This is a highly fragile construct, quick but mainly dirty and not really recommended unless you are out of other options.