Search code examples
cpointersstrcmp

strcmp not working, finds it on second loop iteration


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


Solution

  • strcmp() return 0 when they are equal. You are returning if one is greater or less than the other.