作者:U友48805799 | 来源:互联网 | 2023-05-18 14:34
Imquiteunfamiliarwithhowpointerswork.Imworkingwithafunctionthatcallbacksafunctionw
I'm quite unfamiliar with how pointers work. I'm working with a function that callbacks a function with a void *
context as an argument.
我对指针的工作方式很不熟悉。我正在使用一个函数来回调一个带有void * context作为参数的函数。
How would I go about assigning an array of strings to a void *
and then retrieving them?
我如何将一个字符串数组分配给void *然后检索它们?
char callback_value[2][16];
snprintf(callback_value[0], sizeof(callback_value[0]), "string1");
snprintf(callback_value[1], sizeof(callback_value[1]), "string2");
// pass an array of strings into the void * callback context
void *callback_cOntext= callback_value;
// Illustration only, doesn't work
// retrieve it here
char **retrieved_strings = (char **)callback_context;
printf("%s", retrieved_strings[0]); // Want "string1"
printf("%s", retrieved_strings[1]); // Want "string2"
1 个解决方案