I need to pass an array of structures defined in a file "file1.c" to a function, lets say "myFunc()", defined in another file "file2.c". The thing is that I don't know how to set the prototype of myFunc() in my header file "header.h" or in the function itself in my file2.c because the struct will only be defined in file1.c . Here is an example.
file1.c
#include "header.h"
#define dim 30
#define searchAgents 30
struct Wolf{
double pos[dim];
double fitness;
}Pack[searchAgents];
int main(){
myFunc(Pack); //not sure it's ok
return 0;
}
file2.c
#include "header.h"
void myFunc(struct Wolf Pack[]){ //I don't know how to set this argument
Pack[0].pos[0] = 1; //just an example
}
header.h
#ifndef HEADER_H_
#define HEADER_H_
void myFunc(struct Wolf); //I don't know how to set this prototype
#endif
I read about passing structures to functions but it's different when you have your function defined in another file. Thanks for your time.
void myFunc(struct Wolf Pack[]);in header.h. Probably you want thesearchAgentsdefine in there as well so that you know how many wolves there are in myFunc(). (You are not passing a structure but a pointer to the first structure in thePackarray.)