For example, I have in the main file
1) char ** array[NUMBER];
2) array = build_array();
and in an imported file
char ** build_array()
{
char ** array[NUMBER];
strings[0] = "A";
strings[1] = "B";
return (char *) strings;
}
However, at line 2 in the main file, I get the error: "incompatible types when assigning to type 'char **[(unsighed int)NUMBER]' from type 'char **'
What am I doing wrong? Any suggestions or advice would be appreciated. Thank you in advance.
There seem to be some confusion about what a string is in C. In C, a null terminated sequence of
chars is considered a string. It is usually represented bychar*.You pretty much can’t return an array, neither a pointer to a local array. You could however pass the array to
build_arrayas an argument, as well as itssize, and fill that instead.The alternatives are to return a pointer to a global or static allocated array, which would make your function non-reentrant. You probably don’t care about this now, but is bad practice so I would recommend you avoid going that route.