2011-05-07 66 views
6

我想創建一個方法來查找並替換字符串中的字符串,但我似乎在編譯時有一些錯誤。我可以幫助弄清楚發生了什麼事嗎?未定義的引用stricmp

void replaceString(char *find, char *replace) 
{ 
    int len_string,i; 
    char temp[30]; 
    len_string=strlen(find); 
    while(1) 
    { 
     for(i=0;i<len_string;i++) temp[i]=fgetc(edit); 
      temp[i+1]=NULL; 
     /* the stricmp() is used for comparing both string. */ 
     if(stricmp(find,temp)==0) 
     { 
      fprintf(edit,"%s ",replace); 
      fclose(edit); 
      exit(1); 
     } 
     fseek(edit,-(len_string-1),1); 
    }  
} 

我在編譯時得到的錯誤是對stricmp的未定義引用。 我知道這是不正確的編碼約定,但編輯(FILE類型的對象)當前是一個全局變量。

回答

22

stricmp是Windows特有的。如果你不在Windows上,strcasecmp

+6

不僅針對Windows,而且針對微軟的編譯器/庫。我不認爲你會在Windows的其他編譯器中找到它。 – metamatt 2011-05-07 02:24:02

+1

感謝您的幫助 – Jonathan 2011-05-17 03:03:34

+0

Borland Turbo C也提供了此功能。 – 2013-02-14 20:47:34

2

實際上,錯誤是在鏈接時,而不是在編譯時。你的代碼被編譯成一個目標文件,期望在與其它無法找到的目標文件鏈接時找到stricmp的實現。因此錯誤:「未定義的參考stricmp」。正如bmargulies指出的那樣,該實現僅在Windows庫中可用。如果你在POSIX兼容系統上,你可以切換到strcasecmp()。