truncate a file
I want to truncate a file starting from some point of it.
The code looks as follows:
fseek(f,50,SEEK_SET); // for example 50 bytes from the start
// ???????? // how to trim it after setting the
// file pointer?
Maybe there is a way of putting an EOF character at this point, or truncating it some other way?
Please help, thanks.
dont know if putting EOF at that place will work (though if it works
then it's a better way) but there is another way...read 50 bytes
from start into a buffer ,close the file ,reopen it with "w+" &
write that buffer back into file...
It works this way, but it is not exactly what i need. I need to hash some file before, than add to this file hash value. Then I must decompose the whole file, take the hash again and compare.
The problem is that the file structure must be identical to the original. And while reading and writing the buffer to a string, carriage return characters are not maintained, and the documents differ slightly.
Although the file compare function doesn't see the difference, the hashing function returns different results.
So, I need to trim the file, not to rewrite it.
But thanks anyway
Maybe someone knows the solution???