[英]Conflicting types for function “remove”
我有這個代碼用於我正在做的鏈表。 在添加刪除功能之前,它運行良好。 添加后,后面的錯誤會彈出。 我已經初步確定了它,因為我無法想到造成問題的原因。
#include <stdio.h>
#include <stdlib.h>
struct node
{
int value;
struct node* next;
};
typedef struct node Node;
typedef Node* NodePtr;
void push(int value, NodePtr *start);
void add(int value, NodePtr *start);
void pop(NodePtr* start);
void remove(NodePtr* start); //line 16
void traverse(NodePtr* start);
int main(void)
{
NodePtr first = NULL;
push(2, &first);
add(3, &first);
printf("%d, %p\n", first -> value, first -> next);
printf("%d, %p\n", first -> next -> value, first -> next -> next);
push(4, &first);
add(5, &first);
printf("%d, %p\n", first -> value, first -> next);
printf("%d, %p\n", first -> next -> value, first -> next -> next);
pop(&first);
pop(&first);
printf("%d, %p\n", first -> value, first -> next);
printf("%d, %p\n", first -> next -> value, first -> next -> next);
remove(&first);
add(6, &first);
printf("%d, %p\n", first -> value, first -> next);
printf("%d, %p\n", first -> next -> value, first -> next -> next);
return 0;
}
//push node to beginning
void push(int value, NodePtr *start)
{
NodePtr newStart = malloc(sizeof(Node));
if(newStart == NULL)
{
return;
}
newStart -> value = value;
newStart -> next = *start;
*start = newStart;
}
//add node to end
void add(int value, NodePtr *start)
{
NodePtr newNode = malloc(sizeof(Node));
if(newNode == NULL)
{
return;
}
newNode -> value = value;
newNode -> next = NULL;
NodePtr current = *start;
while((current)->next != NULL)
{
current = current -> next;
}
current -> next = newNode;
}
//pop beginning node
void pop(NodePtr* start)
{
NodePtr trash = *start;
(*start) = (*start)->next;
free(trash);
}
//remove last node
void remove(NodePtr* start) //line 87
{
NodePtr current = *start;
while((current)->next != NULL)
{
if(current->next == NULL)
{
break;
}
current = current -> next;
}
NodePtr trash = current -> next;
current -> next = current;
free(trash);
}
//goes through list
void traverse(NodePtr* start)
{
NodePtr current = *start;
while((current -> next) != NULL)
{
current = current -> next;
}
}
這是錯誤
~/C-Programs> make zelda
cc -g -Wall -Wextra -lm -std=c99 zelda.c -o zelda
zelda.c:16: error: conflicting types for ‘remove’
/usr/include/stdio.h:177: note: previous declaration of ‘remove’ was here
zelda.c:87: error: conflicting types for ‘remove’
/usr/include/stdio.h:177: note: previous declaration of ‘remove’ was here
make: *** [zelda] Error 1
我認為這與我如何初始化它有關,但我沒有發現拼寫錯誤/不正確的參數。 誰知道是什么原因?
在<stdio.h>
中有一個名為remove()
的C標准函數,它與你自己的remove
相沖突。 最簡單的解決方案是將您的函數重命名為my_remove()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.