strcmp 不起作用,在第二次循环迭代中找到它
int compare_filenames(char* data, char* filename){
//note: we only have 31 directory/file entries within a block
int i;
int offset;
//printf("argument %s\n", filename);
for(i = 0; i < BLOCK_SIZE; i+=16){
if(strcmp(filename, &data[i])){
offset = i + 12;
return data[i+12];// double check here
}
}
return ERR_FILE_NOT_FOUND; //didn't find it within
}
对于某些原因,即使第一个元素位于开头,strcmp 也会经历两次循环迭代
int compare_filenames(char* data, char* filename){
//note: we only have 31 directory/file entries within a block
int i;
int offset;
//printf("argument %s\n", filename);
for(i = 0; i < BLOCK_SIZE; i+=16){
if(strcmp(filename, &data[i])){
offset = i + 12;
return data[i+12];// double check here
}
}
return ERR_FILE_NOT_FOUND; //didn't find it within
}
for some reson strcmp goes through two loop iterations even when the first element is right at the beginning
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当它们相等时 strcmp() 返回 0。如果其中一个大于或小于另一个,您就会返回。
strcmp() return 0 when they are equal. You are returning if one is greater or less than the other.
您想要执行
strcmp(filename, &data[i]) == 0
。0 表示字符串之间匹配,计算结果为 false...
You want to do
strcmp(filename, &data[i]) == 0
.0 indicates match between strings, which evaluated as false...