如何解决为什么我的strcasecmp函数会带来错误消息? C
我正在研究CS50 pset5拼写器,现在我正在使用检查功能。我使用strcasecmp
不区分大小写地比较两个字符串。我正在使用cs50 Ide(他们在pset1中给我们的代码)编码,而我的strcasecmp
函数带来了以下错误消息:
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
这是我检查功能的代码:
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;
}
我包括了这些标题:
#include <ctype.h>
#include <stdio.h>
#include <sys/resource.h>
#include <sys/time.h>
#include <string.h>
#include <stdlib.h>
#include "dictionary.h"
请帮助我找到问题所在。我知道它在strcasecmp
函数中,但是我不知道在哪里。如果有人有任何想法,请告诉我。我已经坚持了几个星期的拼写检查。谢谢。
解决方法
根据POSIX 7 strcasecmp()
documentation:
简介
#include <strings.h> <==== NOTE the second "s" int strcasecmp(const char *s1,const char *s2);
#include
的正确strcasecmp()
是strings.h
,而不是string.h
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。