tell me how to overwrite a binary file completely deleting its contents without deleting the file itself?
Here I know that in other languages there are modes of opening a file, and there is a mode before writing there is a mode of overwriting.
I have already encountered such a problem, I have a code that stores the current open orders of the terminal in a file
void WriteData(Order &arr[]){
PrintFormat("Saving data to a file...");
ResetLastError();
int handle=FileOpen(save,FILE_READ|FILE_WRITE|FILE_BIN|FILE_COMMON);
if(handle!=INVALID_HANDLE)
{
FileSeek(handle,0,SEEK_SET);
FileWriteArray(handle,arr,0,WHOLE_ARRAY);
PrintFormat("File saved successfully!");
PrintFormat("Stored items in an array: %d",ArraySize(arr));
FileClose(handle);
}
else
Print("Failed to open the file, error ",GetLastError());
}
Everything is fine I open two orders in the terminal and they are properly saved to a file
But the trouble is that when I close one order, I have only 1 structure with an active order in the array (I have already checked this) but
there is still a record of the old order in the file.
I suspect that when writing bytes smaller than in the file, it just writes them from the first byte and that’s it, and does not delete the old data.
How can this be defeated? what would the file be overwritten and written again, provided that I can not delete the file from the disk?
0x41
All I’m anyways stupid – there should have just removed the flag
FILE_READ