簡體   English   中英

GCC |警告:隱式聲明函數'_stricmp'[-Wimplicit-function-declaration] |

[英]GCC |warning: implicit declaration of function '_stricmp' [-Wimplicit-function-declaration]|

寫在純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");

那么為什么錯誤/警告呢?

也許你可以手動將字符串轉換為全部小寫,然后使用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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM