[英]How do I pass an array of character pointers as void *, then cast back to array of character pointers?
I'm passing an array of character pointers to sqlite3_exec
, which takes 1 parameter and presents it as a void *
, but then I want to access it as the array of character pointers in the callback function. 我将一个字符指针数组传递给
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;
}
How do I access it after I pass it? 我通过后如何访问它?
This works for me: 这对我有用:
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]);
}
Here's simple program that demonstrates the concept. 这是演示概念的简单程序。
#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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.