I'm trying to store 4 arrays in an array, and for some reason, the last value keeps overriding the previous three values. For example, if 123; 456; 789; 987
were inputted into the code below, ipadr[0] - ipadr[4]
would all only store 123
. I've tested to make sure that numConvert()
is working, and within numConvert
, 4 different arrays of ints
are returned, but only numConvert(d)
is the ipadr
array (stored 4 times).
Also, is my syntax / code correct in order for this function to return ipadr
as an array of arrays (int**
)? Why do you need to make it static int*
when initializing the array?
I'm new to C and this has been really frustrating me. Any help would be incredibly appreciated. Thank you in advance!!
int** ipConvert(int a, int b, int c, int d){
static int* ipadr[4];
ipadr[0]=numConvert(a);
ipadr[1]=numConvert(b);
ipadr[2]=numConvert(c);
ipadr[3]=numConvert(d);
return ipadr;
}
numConvert code:
int* numConvert(int dec) {
static int hold[8];
...
return hold;
}