Writing to file truncates even with FILE_READ|FILE_WRITE

 

Hello,


As the title says, I have this bit of testing code, but the file has only one "1" no matter how many times I run it. What am I missing?


Thanks!


int handle;
handle = FileOpen("test.txt",FILE_BIN|FILE_READ|FILE_WRITE);
FileWrite(handle,"1");
 
Mosho:

Hello,


As the title says, I have this bit of testing code, but the file has only one "1" no matter how many times I run it. What am I missing?


Thanks!


If you want to write to .txt file, use FILE_CSV not FILE_BIN. 

And close the opened file after that. 

 
Mosho:

Hello,

As the title says, I have this bit of testing code, but the file has only one "1" no matter how many times I run it. What am I missing? 

When you open the file again the pointer is at the start of the file,  you then overwrite the existing '1'  with a new '1' . . .  you need to seek to the end of the file before writing to it.  There is example code in the FileSeek() documentation.
FileSeek(handle, 0, SEEK_END);
//---- add data to the end of file
Reason: