I am desperately stuck please help.....

I am trying to use a structure which can be accessed and changed by my main c file as well as some header files which I am creating to go with it.

I have tried a few methods, but have been unsuccessful.

My last atempt took the following form:


The main file included two header files, one header file which held the structure definition and declared the array of structures, the other held a function which added data elements to the structure. The main file also needs to be able to add data and read data to and from the structure.

For example:

main.c
------------------

Code:
#include <header1.h>
#include <header2.h>

int main(void){
      
MyFunction();

}

header1.h
-------------------

Code:
struct Data{
int data1;
char data2[20];
};

struct Data structArray[20];

header2.h
------------------

Code:
#include <header1.h>

void MyFunction();

void MyFunction(){

structArray[0].data1 = 2;
structArray[0].data2[0] = 's';
}


Any help is much appreciated, thanks in advance