-6
// issue with the following not returning info or just stalling... but no errors
static int callback(void *voidParam, int argc, char **argv, char **azColName)
{   
    static int k = 0;
    myReturn structReturn;

    char *cTempF = (argv[0] ? argv[0] : "NULL");
    memcpy(&structReturn.cFirstName, cTempF, sizeof(cTempF));// tried strlen(cTempF)... no help

    memcpy(voidParam + k * sizeof(structReturn), &structReturn, sizeof(structReturn));

    k++;
}

myReturn *structReturn = (myReturn*)malloc(sizeof(myReturn) * 20);

rc = sqlite3_exec(db, pSQL, callback, structReturn, &zErrMsg);

typedef struct ReturnTag
{
    char cFirstName[100];
    char cLastName[100];
    short int iAge;
}myReturn;
4

1 に答える 1

1

それを解決しました...必要: memset(&structReturn.cFirstName, '\0', 100);

static int callback(void *voidParam, int argc, char **argv, char **azColName)
{   
    static int k = 0;
    myReturn structReturn;

    char *cTempF = (argv[0] ? argv[0] : "NULL");
    memset(&structReturn.cFirstName, '\0', 100); // <--- needed here
    memcpy(&structReturn.cFirstName, cTempF, strlen(cTempF));

    memcpy(voidParam + k * sizeof(structReturn), &structReturn, sizeof(structReturn));

    k++;
}
于 2012-06-29T23:17:22.910 に答える