我不斷收到壞指針。誰能告訴我我做錯了什麼?搜索字符串數組中的字符串
int SearchString(char* arr[], char* key, int size)
{
int n;
for (n = 0; n < size; ++n) {
if (strcmp(arr[n], key)) {
return n;
}
}
return -1;
}
char str[][16] = { "mov","cmp","add","sub","lea","not","clr","inc","dec","jmp","bne","red","jrn","psr","rts","stop"};
if(SearchString(str,"word",16) == -1){ return FALSE;}
你的'str'是一個由16個字符串組成的數組(編譯器自動創建了16個),每個字符串可以包含15 + 1個字符(指定爲第二維)。你可以用'char str [] [4] = {「mov」,「cmp」,...};'if'(strString(str,「word」,sizeof str/sizeof * str) == -1)/ * ... * /;' – pmg 2012-01-13 10:23:32