Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: conflicting types for function, function declared in header file

so I'm trying to compile a multifile program using makefiles and header files etc. I've got this one program that I keep on getting the same error for even though I've double checked the type a million times. Help!

Errors:

search.c:11: error: conflicting types for 'search' search.h:1: note: previous declaration of 'search' was here

This is my .h file

int search(struct intnode** root, int lookingfor, int* counter);

This is my .c file

#include "search.h"
#include "intnode.h"
#include <stdlib.h>
#include <stdio.h>

/*
Usage:
  search(root, value);
*/

int search(struct intnode** root, int lookingfor, int* counter) {

  /*COMPARE TO ROOT KEY*/
  /*IF EQUAL*/
  if(int_compare(lookingfor, (*root)->key) == 0) {
    printf("%d exists in tree", lookingfor);
    counter++;
    if ((*root)->R != NULL && (*root)->key == (*root)->R) {
      search((*root)->R, lookingfor, *counter);
    }
  }

  /*IF GREATER THAN AND THERE IS A CHILD*/
  else if(int_compare(lookingfor, (*root)->key) == 1 && (*root)->R != NULL) {  
    search((*root)->R, lookingfor, *counter);
    counter++;
  }

  /*IF LESS THAN AND THERE IS A CHILD*/
  else if(int_compare(lookingfor, (*root)->key) == 2 && (*root)->L != NULL) {
    search((*root)->L, lookingfor, *counter);
    counter++;
  }
  return NULL;
}
like image 879
LollyW Avatar asked Oct 30 '22 19:10

LollyW


1 Answers

Make sure intnode is defined before search() is declared.

like image 146
mksteve Avatar answered Nov 15 '22 05:11

mksteve