我遇到了几个编译错误,但我无法弄清楚。这可能很简单,但我无法弄清楚。我猜对指针的引用必须改变,但我不知道到底是什么。我试图更改指针,但它仍然会出错。我将不胜感激。这些错误是:
passing argument 1 of 'compare' from incompatible pointer type
expected 'struct person *' but argument is of type 'char *'
passing argument 2 of 'compare' from incompatible pointer type
expected 'struct person *' but argument is of type 'char *'
struct person *insert(struct person *head, char *personName, int personAge, int (*compare)(struct person *a, struct person *b))
{
struct person *new;
new = (struct person*)malloc(sizeof(struct person));
if(new == NULL)
fprintf(stderr,"Couldn't allocate memory!");
new->name = personName;
new->age = personAge;
if(head == NULL)
{
new->next = head;
head = new;
}
else
{
while(head != NULL)
head = head->next;
//compile errors
if(compare(new->name,head->name) < 0)
{
new->next=head;
head->next=NULL;
}
else
{
head->next = new;
new->next = NULL;
}
}//else
return head;
}//method
//----------------------------compare--------------------------------//
int compare(struct person *a, struct person *b)
{
int result = strcmp(a->name, b->name);
return result;
}