我得到這個錯誤:獲取有關的char *錯誤使用STRCMP(字符*,字符*)
$ gcc -Wall -g translate.c support.c scanner.c -o translate
support.c: In function ‘translate’:
support.c:148:13: warning: passing argument 1 of ‘strcmp’ from incompatible pointer type [enabled by default]
compareNum = strcmp(dict[i], token);
^
In file included from /usr/include/stdio.h:29:0,
from support.c:1:
/usr/include/string.h:28:6: note: expected ‘const char *’ but argument is of type ‘char **’
int _EXFUN(strcmp,(const char *, const char *));
^
,這裏是功能轉換()
int
translate(char* token, char** dict[], int dictLength)
{
int i = 0;
int compareNum;
for(i=0;i<dictLength;i++)
{
if(i % 2 == 0)
{
compareNum = strcmp(dict[i], token);
++i;
if(compareNum == 1)
{
return i;
}
}
}
return 0;
}
一些原因我正在傳遞字典[我],這是一個字符串數組,我試圖比較數組的每個偶數元素的字符串標記,但它說它的char **。我知道該數組是char **,但不是該元素是char *?
字符** []是字符數組* *,不是char *數組。 – IdeaHat 2014-09-10 18:24:12
顯示你的字典的聲明 – Pradheep 2014-09-10 18:25:06
@Pradheep他做了,它的函數的參數 – IdeaHat 2014-09-10 18:25:27