0
我寫這個函數刪除鏈表的元素:按一定標準
List* delPaintingCode(List* head, char *code)
{
List *p,*q;
for(p=head;p!=NULL;q=p,p=p->next)
{
if(!strcmp(code,p->code))
{
if (p==head)
{
q=head;
head=p->next;
free(q);
}
else
{
q->next=p->next;
free(p);
p=q;
}
}
}
return head;
}
,當我把它在另一個功能:
void delpainting()
{
char code[50];
printf("code ");
scanf("%s",code);
List *head=NULL;
head=delPaintingCode(filetolist,code);
}
程序崩潰等等。我有一個警告:passing argument 1 of delPaintingCode from incompatible pointer type
那麼我應該如何將字符串傳遞給函數呢?
什麼是'filetolist'? – mtijanic
「我應該如何將字符串傳遞給函數」 - 它看起來像你應該問「我應該將哪個'List'指針傳遞給函數,這個警告不是隨機的。 – WhozCraig