Hello everyone, I'm an amateur C programmer working on what every amateur programmer wants to do: make a game. In my case a text adventure, though it's not very far along yet. Anyways, I'm having trouble with passing a pointer to a static array from one function to another. Here's the important parts of my code:
Here's what happens when I compile "my_functions.c."Code://test_run.c #include <stdio.h> #include "my_functions.h" int main() { long *array_var=my_function(); printf("%ld\n",array_var[0][1]); return 0; } //my_functions.c #include <stdio.h> #include "my_functions.h" long *my_function() { static long array_var[10][2]; /*some other declarations*/ /*values are added to the array by use of a while loop*/ return array_var; } //my_functions.h long *my_function()
If I change the last line of my_functions.c from "return array_var" to "return *array_var", the warning goes away. This doesn't make sense to me.Code:>c99 -c my_functions.c -I. >warning: return from incompatible pointer type
And in either case when I try and compile "test_run.c":
Needless to say, when I remove the subscripts it compiles, but I print out some useless number.Code:>c99 test_run.c my_functions.o -I. >error: subscripted value is neither array nor pointer
Can someone help me out?