FileSeek end of file isn't working for me

 

Data in the file keeps getting overwritten.



handle = FileOpen("xxxxxx_log.csv", FILE_CSV|FILE_WRITE, ";");
if (handle > 0)
{
FileSeek(handle, 0, SEEK_END);

for(int a = 0; a < num_indicators; a++)
{
FileWrite(handle, log_time, a, "value", buy_close_score);
FileWrite(handle, log_time, a, "buy_score", buy_score);
FileWrite(handle, log_time, a, "buy_close_score", buy_close_score);

for(int b = 0; b < 4; b++)
{
FileWrite(handle, log_time, a, element_list[b], config[a][element_list[b]]);
}
}

FileClose(handle);
}

 
Hello Gozer,

If FILE_WRITE does not combine with FILE_READ, a zero-length file will be opened. If even the file containd some data, they will be deleted. If there is a need to add data to an existing file, it must be opened using combination of FILE_READ | FILE_WRITE.

better have another looksee at docs for FileOpen() as your code is doing what you asked...


A while back I put this into my I/F function to FileOpen() - to remind me because I always got in muddle when reading docs - maybe will clear up docs missread.

Mind you - my writing is how my brain works and you might just get even more confused ;o)

    NOTICE how Read|Write modes used to ensure file not zeroised IF exists so can fileseek to end... (ref:***always*** below)
    
    [write to new [CSV|BIN] file]    for CSV file iMode actual not reqd as function DEFAULT iMode=FILE_CSV|FILE_WRITE
                                    for BINary file actual must be iMode=FILE_BIN|FILE_WRITE
                                    open/create new [CSV|BIN] file for writing
                                    IF file exists THEN contents cleared
                                    
    [add/append+read to existing file]        specify iMode of [FILE_CSV|FILE_BIN]|FILE_READ|FILE_WRITE
                                    IF file !exist THEN file will be created via FILE_WRITE
                                    ***always*** FileSeek(iFh,0,SEEK_END) prior adding data
                                    ***always*** FileSeek(iFh,0,SEEK_END) prior adding data
                                    ***suggest*** caller issues FileSeek()
                                
    [read existing file]            specify iMode of [FILE_CSV|FILE_BIN]|FILE_READ
                                     only opens IF file exists

hth


oh yes...please excuse my writing method! as I use kinda Backus Naur shorthand, kinda...!

so for me at least "[abc|def]" means/can read: abc or def

eg, read existing file: can be, "FILE_CSV|FILE_READ" or "FILE_BIN|FILE_READ"


seem to remember Perl does this sorta regex syntax..., to many under the bridge - all merge together at my grey cell time of life - LOL

 
Thank you! That fixed it.
Reason: