我将一个字符指针数组传递给sqlite3_exec
,它接受1个参数并将其显示为void *
,但后来我想将其作为字符指针数组访问回调函数。
char *output_params[] = {"one", "two"};
result = sqlite3_exec(db, sql_statement, callback, output_params, &zErrMsg);
....
static int callback(void *param, int argc, char **argv, char **azColName) {
// How do I access my character array?
char *output_params[2] = (char **)param;
}
我通过后如何访问它?
答案 0 :(得分:5)
这对我有用:
int callback(void *param, int argc, char **argv, char **azColName)
{
const char** p = (const char **)param;
printf("%s\n", p[0]);
printf("%s\n", p[1]);
}
这是展示这一概念的简单程序。
#include <stdio.h>
void foo(void* in)
{
char **p = (char**)in;
printf("%s\n", p[0]);
printf("%s\n", p[1]);
}
void main(int argc, char** argv)
{
char *output_params[] = {"one", "two"};
foo(output_params);
}