why do I get the error "conflicting types for..." ?

Discussion in 'C' started by punto e basta, Aug 9, 2011.

  1. punto e basta

    punto e basta New Member

    Joined:
    Aug 9, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    This is my code. The types are identical as far as I can see... If anyone could point out the error I'd be grateful. By the way I'm trying to implement a very simple singly-linked list. Any comments or suggestions would are kindly welcomed. Thanks!

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    //void list_insert (int k, struct node* head, struct node* curr);
    
    int main()
    {
        struct node
        {
            int numdata;
            struct node* next;
        };
    
        struct node* head;
        struct node* curr;
        head=NULL;
        curr=NULL;
    
        list_insert(1, head, curr);
        list_insert(2, head, curr);
        list_insert(3, head, curr);
    
        return 0;
    }
    
    void list_insert (int k, struct node* head, struct node* curr)
    {
        curr->numdata=k;
        curr->next=head;
        head=curr;
    }
    
    void show_list(node* head)
    {
        node* curr;
        curr=head;
        printf("\n");
        while(curr!=NULL)
            printf("%d ",curr->numdata);
        printf("end of list\n")
    }
    
    *****************
    It says: "conflicting types for 'list_insert.' " Why?:(
     
    Last edited by a moderator: Aug 9, 2011
  2. codesAllOver

    codesAllOver New Member

    Joined:
    Aug 9, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Well, you have declared Structure Node inside the main method so the declaration is visible only to the main method.
    Rest of teh compiler doesn't know what a node is, so in order to use this in all the functions of your program just declare it out side the main block....and your problem should be solved.
     
  3. xpi0t0s

    xpi0t0s Mentor

    Joined:
    Aug 6, 2004
    Messages:
    3,009
    Likes Received:
    203
    Trophy Points:
    63
    Occupation:
    Senior Support Engineer
    Location:
    England
    Also why is the prototype commented out? Without this the compiler will assume list_insert is defined
    Code:
    int list_insert();
    
    so if you don't want that, use prototypes and DON'T comment them out.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice