in C code I am stuck to pass a struct array to a function, here is the code that looks like my problem:
typedef struct
{
int x;
int y;
char * str1;
char * str2;
} Struct1;
void processFromStruct1 (Struct1 * content []);
int main ()
{
Struct1 mydata [] =
{{1,1, "black", "cat"},
{4,5, "red", "bird"},
{6,7, "brown", "fox"},
};
processFromStruct1 (mydata); // how?! ?? can't find correct syntax
return 0;
}
void processFromStruct1 (Struct1 * content [])
{
printf ("% s", content [1] -> str1); // if I want to print 'red', is this right?
...
}
A compilation error in msvc looks something like this:
error C2664: 'processFromStruct1': cannot convert parameter 1 from 'Struct1 [3]' to 'Struct1 * []'
1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
How to solve this? Hh
source share