currently my code looks like this.

int finds_reading_length(FILE* the_open_file, int the_block_size)

    BYTE* buffer[the_block_size + 1];

    int bytes_read = fread(buffer, 1,the_block_size, the_open_file);
    return bytes_read;

But I don't think it is working, because it always returns 512.

the_block_size = 512;

Am I doing something wrong here ?

EDIT: I found out what I was doing wrong.

I was fseek() 512 bytes back, so every time i read the file. no matter what the function will always return 512 bytes, even if i only read 4 bytes in the first place.

silly me


Not sure what this function is meant to do.

Why do you think the 512 is wrong? You tell fread to read the_block_size blocks of size 1, and it returns the number of blocks successfully read, which due to the block size of 1 is the number of bytes read. Since you fseek back before freading each time, you would never hit the end of the file that way, and would always read 512 bytes (assuming the file has at least 512 bytes).

I have some serious issue with the BYTE* buffer[the_block_size + 1];. This allocates space for the_block_size + 1 pointers to BYTE, which makes little sense when using it for fread.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .