struct group {
char *name;
struct user *users;
struct xct *xcts;
struct group *next;
};
int add_group(Group **group_list_ptr, const char *group_name) {
printf("%p\n",group_list_ptr);
*group_list_ptr = malloc(sizeof(struct group));
printf("%p\n",*group_list_ptr);
printf("%p\n",(*group_list_ptr)->name);
(*group_list_ptr)->name = malloc(sizeof(*group_name));
printf("%p\n",(*group_list_ptr)->name);
strncpy((*group_list_ptr)->(*name), "hello", strlen(*group_name));
//printf("%s\n",(*group_list_ptr)->name);
return 0;
}
我如何为 *name 赋值。在为结构分配内存后,我为名称分配内存
strncpy((*group_list_ptr)->(*name), "hello", strlen(*group_name));
我正在用“hello”对其进行测试,但我想复制 const char *group_name。
我收到错误
lists.c:24:32: error: expected identifier before ‘(’ token
lists.c:24:32: error: too few arguments to function ‘strncpy’