【发布时间】:2015-04-05 21:42:58
【问题描述】:
我有以下功能:
void get_name(char *a)
{
char format[10];
sprintf(format, "%%%ds", SIZE-1);
scanf(format, a);
}
然后我在另一个函数中调用它,如下所示:
CListNode *initialize_list(int n)
{
CListNode *end, *new, *first;
CListNode *head=NULL;
int i;
char new_name[10];
first=(CListNode *) malloc(sizeof(CListNode));
strcpy(first->name, get_name(new_name));
first->next=head;
head=first;
for (i=0; i<n-1; i++) {
end=(CListNode *) malloc(sizeof(CListNode));
strcpy(end->name, get_name(new_name));
first->next=end;
end->next=NULL;
}
return end;
}
CListNode 所在的位置
typedef struct node
{
char name[10];
struct node * next;
} CListNode;
但我收到此错误“Passing 'void' to parameter of in compatible type 'const char *'”两次(每个 strcpy 1 个)。
我做错了什么?
【问题讨论】: