【发布时间】:2015-03-17 14:34:04
【问题描述】:
我已经定义了一个结构来保存一组任何类型的值,这就是为什么 void **data.如果有人帮助我如何通过 void 指针数组打印值指针,我将不胜感激。
这是结构。
typedef struct item{
void **data;//array of void pointer to store names of the group-members
int count;//number of members in the group
struct item *next; //pointer to the next group in the pool queue
} group;
现在,假设一个组的创建如下:
group *gp = (group*) malloc(sizeof(group));
void *a[2];
a[0] = (void*) "John";
a[1] = (void*) "Jim";
gp->data = a;
gp->count = 2;
在某些时候,可能在另一个函数内部,如果我需要打印组节点的值数组,我应该编写什么代码?这是这样一个函数:
void print_group_node(group *gp)
{
//I have the check for vp==NULL here
void **vp = gp->data;
int c = gp->count;
int i;
for(i = 0; i < c; i++)
printf();//what should I write here
//other codes here
}
谢谢。
【问题讨论】:
-
printf("%s \n", (char *)vp[i])