|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
truncate a file
I want to truncate a file starting from some point of it.
The code looks as follows: FILE *f; f=fopen("name","r+"); fseek(f,50,SEEK_SET); // for example 50 bytes from the start // ???????? // how to trim it after setting the // file pointer? fclose(f); Maybe there is a way of putting an EOF character at this point, or truncating it some other way? Please help, thanks. |
|
#2
|
|||
|
|||
|
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... HTH |
|
#3
|
|||
|
|||
|
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??? |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > truncate a file |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|