<分区>
Possible Duplicate:
How to compare strings in an “if” statement?
我使用的是 C。我的两个字符串与等号 == 运算符相比时不匹配,即使标准输出看起来相同。
考虑其中一个数组以整数数组开始,我通过向每个整数添加“0”并将其加载到另一个 char * 数组中将其转换为字符。
所以现在两个数组都是具有字符和相同标准输出的字符数组,但我的“if”选择结构无法匹配它们。我使用 char * 名称来引用每个数组。
如有必要,我可以发布整个代码。这是一个带有比较的循环:
i=0;
pipx = (char*)malloc(sizeof(char));
sec = (char*)malloc(sizeof(char));
//for (b = 0; b < lengthx; b++){
//reallocate a second array
pipx = (char*)realloc(sec, ((i+1)*sizeof(char)) );
sec = pipx;
//add bitstr[b] to second array
sec[i] = (char)bitstr[b] + '0';
i++;
for (m = 0; m < k; m++){
printf("codex[m].bitx:%s", codex[m].bitx);
printf("sec:%s|\n", sec);
printf("seclen: %i", (int)strlen(sec));
printf("codex[m].bitxlen: %i\n", (int)strlen(codex[m].bitx));
if ((char*)sec == (char*)codex[m].bitx){
printf("This should output: %s", sec);
printf("Here ---------------------- Here");
//allocate the second array to zero
i=0;
sec = (char*)malloc(0);
}
}
}