【发布时间】:2014-04-25 12:02:57
【问题描述】:
我正在尝试比较位的模式,为此我有一个将模式保存为字符串的结构。然后我想将该字符串与我构建的另一个字符串进行比较。我正在使用 strcmp,但是它匹配两个字符串,即使它们不匹配。 这是我的代码
typedef struct
{
int emp;
char *context;
int numOnes;
int numZeros;
}Pattern;
char *patt, str[t+1];
patt = str;
while(count<t){
//printf("Stream: %d\n", stream[end]);
if(stream[end] == 1){
patt[count]= '1';
//writeBit(1);
}
else{
patt[count]='0';
//writeBit(0);
}
end--;
count++;
} //code to build a string
while(i<(1<<t)&&(found==0)){
if((strcmp(patt,patterns[i].context)==0)){
if(patterns[i].numOnes <= patterns[i].numZeros){
prediction = 0;
checkPredict(prediction,stream[end], i);
}
else{
prediction = 1;
checkPredict(prediction,stream[end], i);
}
found = 1;
}
else{
found = 0;
}
i++;
}//comparing string
【问题讨论】:
-
I am using strcmp, however it is matching two strings even though they do not match.你是怎么识别的?你调试了吗?通过打印值进行调试。