Raised This Month: $ Target: $400
 0% 

Problems with reading last line of file


Post New Thread Reply   
 
Thread Tools Display Modes
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
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 07-05-2006 , 06:48   Re: Problems with reading last line of file
Reply With Quote #2

you should use the new file natives, they are much mo betta
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
schnitzelmaker
Senior Member
Join Date: Apr 2006
Location: HERE
Old 07-05-2006 , 07:36   Re: Problems with reading last line of file
Reply With Quote #3

i use allway this to read every line of file:
Code:
new fsize = file_size(filename,1)
for (new i = 0;i<=fsize;i++){
  read_file(filename,i,Array,32,dummy)
  ...
__________________
schnitzelmaker is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 07-05-2006 , 11:08   Re: Problems with reading last line of file
Reply With Quote #4

Quote:
Originally Posted by schnitzelmaker
i use allway this to read every line of file:
Code:
new fsize = file_size(filename,1)
for (new i = 0;i<=fsize;i++){
  read_file(filename,i,Array,32,dummy)
  ...
If you use the new file natives it actually works much better.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
jtp10181
Veteran Member
Join Date: May 2004
Location: Madison, WI
Old 07-05-2006 , 17:49   Re: Problems with reading last line of file
Reply With Quote #5

not only better but it is MUCH faster, with read file everytime you call it, it opens a new file handle and seeks from the start of the file. With the new natives you open the file handle and then just progress through the file using the same handle.
__________________
jtp10181 is offline
Send a message via ICQ to jtp10181 Send a message via AIM to jtp10181 Send a message via MSN to jtp10181 Send a message via Yahoo to jtp10181
Reply



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