views:

2856

answers:

2

In main:

char *myData[500][9]; //dynamic rows??
char **tableData[500]={NULL};         //dynamic rows??
int r;

newCallBack(db, &myData, &tableData, &r);

and passing into function by:

void newCallBack(sqlite3 *db, char** mdat, char*** tdat, int* r )
{

Doesn't seem to like this? Any suggestions? Lots of examples online when you don't know the size, trying them out right now....

Thanks.

+4  A: 

First of all, the problem with myData is that it's the wrong type. char* [][] would require a prototype char*** (a two-dimensional array of strings) in the function you're calling. The function wants a list of strings, which is char* [], or alternatively char[][], if you don't mind limiting the size of the strings.

To get fully dynamic array sizes you'll have to manually allocate (and release!) memory with malloc() and free(), and change the types of your variables to char **myData and char ***tableData.

arnsholt
+2  A: 

If you were to rewrite this as such:

#define NUM_ROWS 500;
#define NUM_COLS 9;

char **myData  = NULL;
char  *tableData = NULL;
int    i;
int    r;

myData = malloc(sizeof(char *) * NUM_ROWS);
if (!myData)
    return; /*bad return from malloc*/

tableData = malloc(sizeof(char) * NUM_ROWS);
if (!tableData)
    return; /*bad return from malloc*/

for (i = 0; i < NUM_ROWS; i++)
{
    myData[i] = malloc(sizeof(char) * NUM_COLS);
    if (!myData[i])
        return;  /*bad return from malloc*/
}

You would then call newCallBack() like this if you just wanted access to the data (myData, tableData, and r):

/*prototype*/
void newCallBack(sqlite3 *db, char** mdat, char* tdat, int r);

/*call*/
newCallBack(db, myData, tableData, r);

Or this if you want to be able to modify what the vars myData and tableData point to and the value of r:

/*prototype*/
void newCallBack(sqlite3 *db, char ***mdat, char **tdat, int *r);

/*call*/
newCallBack(db, &myData, &tableData, &r);
lillq