I want to pass a pointer to pointer to a function, allocate memory in function, fill it with strings and get it back, but all seems not to be working. Program prints nothing outside the function. There is most important pieces of code:
struct record ** getRegEx( int *counter, char** keys )
{
*counter = 0;
//get some records, its number is *counter, max lenght of each string is 64
//COUNTER IS NOT 0! ITS VALUE DEPENDS ON OTHER OPERATIONS I HAVENT WRTTEN HERE
//...
keys =(char ** ) malloc((*counter)*(sizeof(char *)));
for (j = 0; j < *counter; j++)
{
keys[j] = (char* )malloc(64*sizeof(char));
}
strcpy(keys[j],key.dptr);
printf("size %d : \n", sizeof(**keys));//1
printf("size %d : \n", sizeof(*keys));//4
printf("size %d : \n", sizeof(keys[0]));//4
printf("size %d : \n", sizeof(keys));//4
//...
}
/*Out of the function, inside the function OK*/
char** keys;
int count;
results = getRegEx(&count, &keys); //&keys or keys - makes no difference
for(int k=0 ; k< *count;k++) //test
{
printf("keys in db %s: s\n", keys[k]); //nothing!?
}
I have made it works by replacing function header with something like struct record ** getRegEx( int *counter, char*** keys ) (and using *keys and *keys[i] instead of key and keys[i] inside the function). Thanks for All!