Help with errors in compiling

This is a discussion on Help with errors in compiling within the C Programming forums, part of the General Programming Boards category; I am writing a program that works with hash tables using chaining. I have all my functions typed up but ...

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    6

    Help with errors in compiling

    I am writing a program that works with hash tables using chaining. I have all my functions typed up but it keeps giving me the error:

    error: conflicting types for (some function)
    note: previous declaration of (some function) was here

    It says this for all of my functions. I checked all function declarations in the header file and source file and I cant find any errors. Please help.


    Here are the two header files:

    List.h
    Code:
    /*
      list.h: header file containing functions necessary to work with doubly linked lists
    */
    
    
    /*
      structure that contains variables necessary for a node in a linked list
    */
    typedef struct LLnode
    {
      struct LLnode *next;
      struct LLnode *prev;
      int key;
    } LLnode;
    
    /*
      structure that holds a list as a whole
    */
    struct List
    {
      struct LLnode *head;
    };
    
    
    /*
      listSearch searches through a linkd list for a certain key
      input: a linked list and a key to be searching for
      output: a pointer to a node
    */
    LLnode* listSearch(struct List *L, int key);
    
    /*
      listInsert inserts a node at the head of a list
      input: A linked list and a node to be inserted
      ouput: none
    */
    void listInsert(struct List *L, LLnode *x);
    
    /*
      listDelte deletes a node in a list
      input: a linked list and a node to be deleted
      output: none
    */
    
    void listDelete(struct List *L, LLnode *x);
    
    /*
      createNode creates  node with a string as its key
      input: a string to be used as they key
      output: a pointer to a node
    */
    LLnode* createLNode(int key);
    
    /*
      freeLL is used for garbage collection when a node is deleted
      input: a node to be freed
      output: none
    */
    void freeLL(LLnode *x);
    
    /*
      displayLL printsa linked list to the screen
      input: a linked list
      oupute: none
    */
    void displayLL(struct List *L);

    hash.h
    Code:
    /*
      chain.h: header file containing functions necessary to work with hash tables
    */
    
    #include "list.h"
    
    struct Table
    {
      struct List table[100];
      int value;
      int size;
      struct LLnode *node;
    };
    
    void chainHashInsert(struct Table *T, int k);
    
    LLnode* chainHashSearch(struct Table *T, int k);
    
    void chainHashDelete(struct Table *T, int k);
    
    void multiplicationHash(struct Table *T, int k);
    
    void divisionHash(struct Table *T, int k);

    and here is the source file hash.c
    Code:
    #include "hash.h"
    #include "list.h"
    #include <stdlib.h>
    #include <stdio.h>
    
    void chainHashInsert(struct Table *T, int k)
    {
      divisionHash(&T, k);
      T->node = createLNode(k);
      listInsert(T->table[T->value], T->node);
    }
    
    LLnode* chainHashSearch(struct Table *T, int k)
    {
      divisionHash(&T, k);
      T->node = listSearch(T->table[T->value], k);
      return T->node;
    }
    
    void chainHashDelete(struct Table *T, int k)
    {
      divisionHash(&T, k);
      T->node = listSearch(T->table[T->value], k);
      if(T->node != NULL)
        {
          listDelete(T->table[T->value], T->node);
          printf("\nValue deleted");
        }
      else
        printf("\nThat value was not found");
    }
    
    void multiplicationHash(struct Table *T, int k)
    {
      int x;
      x = 2;
    }
    
    void divisionHash(struct Table *T, int k)
    {
      T->value = k % (T->size);
    }

    I haven't implemented the multiplication hash yet but that's besides the point. Any help would be appreciated.

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    6
    oh and here's the source file list.c:

    Code:
    #include "list.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    LLnode* listSearch(struct List *L, int key)
    {
      LLnode *x = malloc(sizeof(LLnode));
      int cmp;
      x = L->head;
      if(x == NULL)
        return x;
      while(x != NULL &&  x->key != key)
        {
          x = x->next;
          if(x == NULL)
            return x;
        }
      return x;
    }
    
    void listInsert(struct List *L, LLnode *x)
    {
      x->next = L->head;
      if(L->head != NULL)
        L->head->prev = x;
      L->head = x;
      x->prev = NULL;
    }
    
    void listDelete(struct List *L, LLnode *x)
    {
      if(x->prev != NULL)
        {
          x->prev->next = x->next;
        }
      else
        L->head = x->next;
      if(x->next != NULL)
        {
          x->next->prev = x->prev;
        }
      else
        L->head = x->next;
      if(x->next != NULL)
        {
          x->next->prev = x->prev;
        }
    
      free(x);
    }
    
    LLnode* createLNode(int key)
    {
      LLnode *x = malloc(sizeof(LLnode));
      x->key =  key;
      x->prev = NULL;
      x->next = NULL;
      return x;
    }
    
    
    void freeLL(LLnode *x)
    {
      if(x != NULL)
        {
          if(x->next != NULL)
            freeLL(x->next);
          free(x);
        }
        }
      else
        return;
    }
    
    void displayLL(struct List *L)
    {
      LLnode *x = malloc(sizeof(LLnode));
      x = L->head;
      printf("\n\nCurrent numbers in list: ");
      while(x != NULL)
        {
          printf("%d <--> ", x->key);
          x = x->next;
        }
    }

  3. #3
    Registered User
    Join Date
    Nov 2011
    Posts
    6
    Ok I figured out the problem but now I have a new problem. It says that all the functions that use T->table[T->value] as a parameter are incompatible types. I thought I knew how to make arrays of structures but I guess not. That parameter should be pointing to an index in the array that is of type struct List. But it gives me an error. So something is wrong.

    Sorry for the multiple posts

  4. #4
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,651
    Your functions take struct List *, but T->table[T->value] is a struct List, not a struct List *.

  5. #5
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,498
    You syntax is generally correct, you just don't have matching types. T->table is an array of 100 List structs, but listInsert et al. take pointers to List structs. You should probably declare table to be an array of pointers to List structs.
    EDIT: Beaten! I'm so slow this week...

  6. #6
    Registered User
    Join Date
    Nov 2011
    Posts
    6
    ahh that makes complete sense. Thank you very much

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors after compiling
    By CroBoss in forum C++ Programming
    Replies: 3
    Last Post: 06-09-2010, 10:21 AM
  2. Compiling errors
    By courtesan in forum C Programming
    Replies: 2
    Last Post: 08-18-2005, 10:52 AM
  3. Compiling errors again
    By Jessica in forum C++ Programming
    Replies: 2
    Last Post: 04-04-2002, 08:47 AM
  4. compiling errors
    By Jessica in forum C++ Programming
    Replies: 5
    Last Post: 04-03-2002, 07:20 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21