2014-08-27 151 views
1

我有一个问题,为什么我的代码不会编译时,我使用strcmpi。我用strcmp测试了这个相同的代码,并且工作。不知道为什么这不起作用。strcmpi代码不会编译,但strcmp会?

这里是编译错误,我得到:

gcc -std=c99 strcmpi_test.c -o strcmpi_test 
strcmpi_test.c: In function 'main': 
strcmpi_test.c:15: warning: implicit declaration of function 'strcmpi' 
strcmpi_test.c:30:2: warning: no newline at end of file 
/tmp/cceKXLcn.o: In function `main': 
strcmpi_test.c:(.text+0x50): undefined reference to `strcmpi' 
collect2: ld returned 1 exit status 



#include <stdio.h> 
#include <string.h> 


int main() 
{ 

    char name[10]; 

    char name2[10] = "bob"; 

    printf("what is your name : "); 
    fgets(name,10,stdin); 

    if(strcmpi(name,name2) == 1) 
    { 

     printf("name == %s name2 == %s your names are the same\n",name,name2); 

    } else { 

     printf("name == %s name2 == %s your names are NOT the same\n",name,name2); 


    } 


    return 0; 

} 
+5

decalred'strcmpi'不是一个标准功能。在Linux上,有'strcasecmp',它不区分大小写的比较。 – 2014-08-27 17:59:06

+1

@MOehm正确,但你也应该提到这个函数只能在''中声明(注意多余的S)。 Linux在''中确实有''但是大多数BSDs没有。 – zwol 2014-08-27 18:10:31

+1

@Zack:好点;我不知道。 (但是我相信OP会查找函数以及声明的位置,一旦知道该名称。) – 2014-08-27 18:33:59

回答

0

strcmpi是不是一个标准的C函数。编译器报告它没有函数strcmpi的声明。

您可以使用循环自己写一个类似的功能和功能touppertolower在头<ctype.h>