Skip to content Skip to sidebar Skip to footer

I'm Not Able To Pass A Callback Function With A New Argument I Added In C

I don't know how to pass a variable into a callback to do some stuff (print json output) inside this function. In sample code there is no other functions i need to pass but with sq

Solution 1:

Your callback's signature

staticintcallback(struct kreq *req, int argc, char **argv, char **azColName)

is wrong. It should be

staticintcallback(void *ptr, int argc, char **argv, char **azColName){
    structkreq *req = (struct kreq *)ptr;

The callback's signature should exactly match the function pointer's format, which, for sqlite3_exec, isint (*callback)(void *, int, char **, char **).

And this

rc = sqlite3_exec(db, "SELECT * FROM hosts;", callback(req), 0, &zErrMsg);

should be

rc = sqlite3_exec(db, "SELECT * FROM hosts;", callback, req, &zErrMsg);

callback(req) calls callback, which is not what you want; you're trying to pass a function pointer to a function, which is done with just the function's name.

Post a Comment for "I'm Not Able To Pass A Callback Function With A New Argument I Added In C"