K
kpamafrederic
Hi all,
I have a little question regarding the subject of the topic. Sorry if it's seems like a silly question but I never really studied C and my knowledge comes from personal projects so I do need to learn.
Currently I'm trying to pass an return a pointer to an array of pointer andI wanted to know how I can correctly implement it. Basically the function is supposed to look into a Database and return all string results in a pointer. Since the caller doesn't know how many results the function will return I was thinking of something like this (note that it is how I implemented it):
int foo( char ***results);
then the caller can walk through the result with something like this :
char **results;
int i=0;
foo(&results);
while ( results != 0 )
{
// do something with this entry.
i++;
}
But I found the prototype of foo not really "self-explanatory". I also thought of something like this :
int foo ( char *result[]);
but I supposed this would means that the result is *const*ant while the user is in charge of freeing the results.
Can somebody explain me how he would've done it please? Thanks you so much for your time.
I have a little question regarding the subject of the topic. Sorry if it's seems like a silly question but I never really studied C and my knowledge comes from personal projects so I do need to learn.
Currently I'm trying to pass an return a pointer to an array of pointer andI wanted to know how I can correctly implement it. Basically the function is supposed to look into a Database and return all string results in a pointer. Since the caller doesn't know how many results the function will return I was thinking of something like this (note that it is how I implemented it):
int foo( char ***results);
then the caller can walk through the result with something like this :
char **results;
int i=0;
foo(&results);
while ( results != 0 )
{
// do something with this entry.
i++;
}
But I found the prototype of foo not really "self-explanatory". I also thought of something like this :
int foo ( char *result[]);
but I supposed this would means that the result is *const*ant while the user is in charge of freeing the results.
Can somebody explain me how he would've done it please? Thanks you so much for your time.