Hi all,
I have a C project consisting of five files as follows:
main.c
file1.c
file1.h
file2.c
file2.h
I have defined an array in file file1.h as follows:
static struct prnc keys[MAXP];
the array was populated in file file1.c
Now I need to use the contents of this array again in file file2.c , I don't get a compilation error when i try to print the cotents of the array in file2.c, but at run time I get nothing as if the code is never encountered. So I tried the following two approaches:
1- I changed the definition of the array in file1.h to:
extern struct prnc keys[MAXP];
This time I got a compilation error generated by references to the array in file file1.c, the error message stated that the array is unknown. Why?
so I tried this:
2- I kept the definition in file1.h as:
static struct prnc keys[MAXP];
and added the following line in file2.c:
extern struct prnc keys[MAXP];
the project compiles but at run time the array seems to be empty.
My question is:
The array is populated in file1.c, and I want to reference its contents in
file2.c
, how can I do that? cause I really don't think that answer is to repopulate it in file2.c! or is it?!
Thanks in advance for your help.