Lost in code
Lost in code

Reputation: 313

Why is my strcasecmp function bringing error messages? (c)

I'm working on cs50 pset5 speller, and right now I'm on the check function. I use strcasecmp to compare two strings case insensitively. I'm coding in cs50 Ide(The one they give us in pset1) and my strcasecmp function brings this error message:

clang -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -c -o speller.o speller.c
clang -ggdb3 -O0 -Qunused-arguments -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wshadow -c -o dictionary.o dictionary.c
dictionary.c:37:12: error: implicit declaration of function 'strcasecmp' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
       i = strcasecmp(word, cursor -> word);
           ^
1 error generated.
Makefile:2: recipe for target 'speller' failed
make: *** [speller] Error 1

Here is my code for the check function:

bool check(const char *word)
{ 
    unsigned int lol = hash(word);
     // TODO
   int i;
   node *cursor =table[lol];;
    while(cursor != NULL)
    {
     
       i = strcasecmp(word, cursor -> word);
      if(i == 0)
      {
          return true;
      }
      cursor = cursor->next;
   
    }
    
    
    return false;
}

And I included these headers:

#include <ctype.h>
#include <stdio.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <string.h>
#include <stdlib.h>
#include "dictionary.h"

Please help me find my problem. I know it's in the strcasecmp function, but I don't know where. If anyone has any ideas, PLEASE tell me. I've been stuck on speller for weeks. Thanks.

Upvotes: 1

Views: 1292

Answers (1)

Andrew Henle
Andrew Henle

Reputation: 1

Per the POSIX 7 strcasecmp() documentation:

SYNOPSIS

#include <strings.h>  <==== NOTE the second "s"

int strcasecmp(const char *s1, const char *s2);

The proper #include for strcasecmp() is strings.h, not string.h.

Upvotes: 4

Related Questions