Raised This Month: $51 Target: $400
 12% 

Find the last line


Post New Thread Reply   
 
Thread Tools Display Modes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-13-2018 , 19:14   Re: Find the last line
Reply With Quote #11

Quote:
Originally Posted by edon1337 View Post
How would I check that?
PHP Code:
//Open file for update (reading and writing).
new iFile fopen"file.txt" "r+" );

//Buffer to read 1 single byte.
new bytVal];

//Buffer for new line to write.
new szNewLine32 ];
    
//Seek to the end of file - 1 (since we want to read the last byte).
fseekiFile , -SEEK_END );

//Read byte.
fread_rawiFile bytVal sizeofbytVal ) , BLOCK_BYTE );

//Seek to the end of the file for writing new line.
fseekiFile SEEK_END );
    
//Format new line. Prefix with '^n' if current last byte is not a new line byte.
formatexszNewLine charsmaxszNewLine ) , "%sNew line" , ( bytVal] == 10 ) ? "" "^n" );

//Write line to file.
fputsiFile szNewLine );
     
//Close file.   
fcloseiFile ); 
__________________
Bugsy is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 01-14-2018 , 09:29   Re: Find the last line
Reply With Quote #12

Quote:
Originally Posted by Bugsy View Post
PHP Code:
//Open file for update (reading and writing).
new iFile fopen"file.txt" "r+" );

//Buffer to read 1 single byte.
new bytVal];

//Buffer for new line to write.
new szNewLine32 ];
    
//Seek to the end of file - 1 (since we want to read the last byte).
fseekiFile , -SEEK_END );

//Read byte.
fread_rawiFile bytVal sizeofbytVal ) , BLOCK_BYTE );

//Seek to the end of the file for writing new line.
fseekiFile SEEK_END );
    
//Format new line. Prefix with '^n' if current last byte is not a new line byte.
formatexszNewLine charsmaxszNewLine ) , "%sNew line" , ( bytVal] == 10 ) ? "" "^n" );

//Write line to file.
fputsiFile szNewLine );
     
//Close file.   
fcloseiFile ); 
Works like a charm, thanks Bugsy!
__________________
edon1337 is offline
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 06:57.


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