I'm trying to have a function set a global variable to the value that i pass it. I know how to do this with something like an int, but i can't seem to get it to work with a string array. Here is the code:
#include "stdio.h"
char *(*(*foo));
void setFunc(char *arr[]);
int main(int argc, char const *argv[]) {
char *bar[] = {"Test", "Test 2"};
setFunc(bar);
printf("%s %s\n", *foo[0], *foo[1]);
return 0;
}
void setFunc(char *arr[])
{
foo = &arr;
}
This outputs: "Test (null)" And is as close as i could get.
I hope i am not missing something stupid. I am pretty new to C and pointers are still pretty confusing.