【问题标题】:GCC |warning: implicit declaration of function '_stricmp' [-Wimplicit-function-declaration]|GCC |警告:函数“_stricmp”的隐式声明 [-Wimplicit-function-declaration]|
【发布时间】:2019-10-13 06:33:02
【问题描述】:

用纯 C.. 编写。

但我已将 string.h 包含为:

#include <string.h>     // for strnlen
#include <stdlib.h>     // for _countof, _itoa fns, _MAX_COUNT macros  
#include <conio.h>      // for  _getch  
#include <process.h>    // for system  
#include <io.h>         // for findfirst  
#include <locale.h>  

在这里调用:

if( argc != 2 )   {
  printf("Usage: extension .001 or .alm only\n");
  return(0);   
}
else printf("Read %d %s\n",argc, argv[1]);


if( !_getcwd((char *)cdir, sizeof(cdir)))    {  
  printf("\n ! ERROR ! obtaining current disc directory!");  
  printf("\n .. any key ..");  
  _getch();  
  exit(-1);  
}
printf("\n Directory: %s\n", cdir);

if(!_stricmp(argv[1],"alm"))
  sprintf(csrch,"*.alm");  
else 
  sprintf(csrch,"*.001");

那么为什么会出现错误/警告?

【问题讨论】:

标签: c


【解决方案1】:

也许您可以手动将字符串转换为全小写,然后使用 strcmp?

int stricmp(const char *string1, const char *string2) {
    char* tmp1 = malloc(sizeof(string1));
    char* tmp2 = malloc(sizeof(string2));

    strcpy(tmp1, string1);
    strcpy(tmp2, string2);

    for (int i = 0; i < strlen(tmp1); i++)
        tmp1[i] = tolower(tmp1[i]);

    for (int i = 0; i < strlen(tmp2); i++)
        tmp2[i] = tolower(tmp2[i]);

    int res = strcmp(tmp1, tmp2);

    free(tmp1);
    free(tmp2);

    return res;
}

【讨论】:

  • 仅供参考,我刚刚运行了带有两个警告的程序,它似乎工作正常。所以上帝知道为什么会发出警告或发出什么警告。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-04-23
  • 1970-01-01
  • 2015-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-07-28
相关资源
最近更新 更多