简体   繁体   English

函数“删除”的冲突类型

[英]Conflicting types for function “remove”

I have this code for a linked list I am doing. 我有这个代码用于我正在做的链表。 Before adding the remove function it was working nicely. 在添加删除功能之前,它运行良好。 After I added it, the error that is later in the post is popping up. 添加后,后面的错误会弹出。 I already initialized it as you can see so I cannot think of what is causing the problem. 我已经初步确定了它,因为我无法想到造成问题的原因。

#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;
    }
}

Here is the error 这是错误

~/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

I would think it has something to do with how I initialized it but I did not find spelling mistakes/incorrect parameters. 我认为这与我如何初始化它有关,但我没有发现拼写错误/不正确的参数。 Anyone know what is the reason? 谁知道是什么原因?

There's a C standard function called remove() in <stdio.h> which conflicts with your own remove . <stdio.h>中有一个名为remove()的C标准函数,它与你自己的remove相冲突。 Easiest solution is to rename your function to something like my_remove() . 最简单的解决方案是将您的函数重命名为my_remove()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM