Hi,
I'm trying to read from a binary file in blocks of constant size(say 512B), and then write it into another file, with fread() and fwrite(). However, if the original filesize is a multiple of 512, I'm always reading an extra block, and if it's not a multiple of 512, my final block will contain partial data, which will then be written to an output file that is a multiple of 512.
I'm doing a while (0 == feof(file)) and within that loop, a fread(&buffer, 512,1,file). How do I eliminate the final block problem? I'm guessing I'll have to find out the size of the data within the blocks and check if it's <512, but I'm not sure how to do that.
I'm trying to read from a binary file in blocks of constant size(say 512B), and then write it into another file, with fread() and fwrite(). However, if the original filesize is a multiple of 512, I'm always reading an extra block, and if it's not a multiple of 512, my final block will contain partial data, which will then be written to an output file that is a multiple of 512.
I'm doing a while (0 == feof(file)) and within that loop, a fread(&buffer, 512,1,file). How do I eliminate the final block problem? I'm guessing I'll have to find out the size of the data within the blocks and check if it's <512, but I'm not sure how to do that.