Suleyman
Suleyman

Reputation: 23

C error: "conflicting types for"

My program includes the following code:

static short index(key)
 unsigned char *key;
{
    long i, sum = 0;
    for (i = 0; key[i]; i++)
        sum += key[i];
    return(sum % TABLE_SIZE);
}

But, it gives following error:

table.c:46:14: error: conflicting types for 'index'
 static short index(key)
              ^

I'm a C newbie, read about prototyping etc., but I cannot solve the problem.

Upvotes: 2

Views: 4714

Answers (1)

merlin2011
merlin2011

Reputation: 75555

index is a function in the C library. If you choose a different name for your function, that error will go away.

From the man page, we see that it takes a const char* and an int.

 #include <strings.h>

 char *index(const char *s, int c);

Upvotes: 5

Related Questions