strcmp不工作,在第二次循环迭代中找到它

时间:2011-04-23 22:27:06

标签: c pointers 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经历了两次循环迭代,即使第一个元素在开头就是

2 个答案:

答案 0 :(得分:4)

strcmp()在相等时返回0。如果一个大于或小于另一个,则返回。

答案 1 :(得分:3)

您想要strcmp(filename, &data[i]) == 0

0表示字符串之间匹配,评估为false ...