Raised This Month: $ Target: $400
 0% 

Problems with reading last line of file


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Infra
Senior Member
Join Date: Aug 2004
Location: California
Old 07-04-2006 , 23:21   Problems with reading last line of file
Reply With Quote #1

Code:
// Match stats - Main
// DO NOT EDIT THIS FILE

0
1
Code:
    // Get match number     if( (half == 1) && (main_in2mapmatch != 1) )     {         if( file_size(stats_file_main, 1) > 2 ) // If there are matches in the stats file         {             read_file(stats_file_main, file_size(stats_file_main, 1) - 1, match_num_str, 31, match_num_len)                         stats_match_number = str_to_num(match_num_str) + 1         }         else         {             stats_match_number = 0                     write_file(stats_file_main, "// Match stats - Main")             write_file(stats_file_main, "// DO NOT EDIT THIS FILE")             write_file(stats_file_main, "")         }                 num_to_str( stats_match_number, match_num_str, 31 )         write_file(stats_file_main, match_num_str)     }     else     {               read_file(stats_file_main, file_size(stats_file_main, 1) - 1, match_num_str, 31, match_num_len)                 stats_match_number = str_to_num(match_num_str)     }

The code above is supposed to read the last line of a file (the last match's id) from a file and increment the id for this match. Or if there are no matches in the file, then make the match number = 0.

The problem: Right now 'stats_match_number' will not increment past 1...

Any help would be appreciated...Thanks!

*EDIT* Nevermind O...Figured out that write_file writes and extra newline/linefeed to the file, so the file line should be: "file_size(stats_file_main, 1) - 2", instead of: "file_size(stats_file_main, 1) - 1"
__________________
--Infra

Last edited by Infra; 07-04-2006 at 23:56.
Infra is offline
Send a message via AIM to Infra
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode