我想在两个 char* 之间进行比较,所以我用 strcmp 来做,看,在调试模式下,strcmp 中的两个 char* 都得到相同的值,但它仍然不会返回 0,它会跳过 if() 条件而不是输入它:
这里来自调试器的图片:http: //img405.imageshack.us/img405/5218/111fi.jpg
Company FindCompany(CompanyL pcompanyList, int companyIdentityDigit)
{
Company companyFound;
char *psearchWord;
psearchWord = (char*)malloc(10*sizeof(char));
switch(companyIdentityDigit) {
case 0:
strcpy(psearchWord , "Pelephone");
break;
case 2:
strcpy(psearchWord , "Cellcom");
break;
case 4:
strcpy(psearchWord , "Orange");
break;
}
while(pcompanyList->next != NULL) {
if(strcmp(pcompanyList->thisCompany->pcompany , psearchWord) == 0) {
free(psearchWord);
return pcompanyList->thisCompany;
}
pcompanyList = pcompanyList->next;
}
free(psearchWord);
return NULL;
}
为什么??