How to read the last lines of file? - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: How to read the last lines of file? (
/showthread.php?tid=144261)
How to read the last lines of file? -
SiJ - 26.04.2010
Hello,
I'm saving player's reports to file like that:
Quote:
[2010-04-21, 11:10] Player_Name: Report goes here
[2010-04-22, 21:12] Player_Name: Report goes here
[2010-04-22, 21:18] Player_Name: Report goes here
[2010-04-22, 21:33] Player_Name: Report goes here
[2010-04-22, 21:40] Player_Name: Report goes here
|
I want to make command, which would read the file and show latest 3 reports (last 3 lines of the file)..
Could anybody help me using
dini ?
Re: How to read the last lines of file? -
SiJ - 27.04.2010
Re: How to read the last lines of file? -
[MWR]Blood - 27.04.2010
I don't know, but I don't think showing only the 3 last reports is possible.
Re: How to read the last lines of file? -
SiJ - 27.04.2010
Oh well.. If it's not possible, I'll try to find another way..
Re: How to read the last lines of file? -
dice7 - 27.04.2010
Well, dini saves stuff using 'keys', so just reset the keys for the last 3 reports with the correct report strings.
Btw, a method using the original file functions
pawn Code:
new
File:Fp = fopen("irc_log.txt", io_read),
thirdLastLine[256],
secondLastLine[256],
lastLine[256],
idx = 0;
while (fread(Fp, lastLine) != 0) idx++;
fseek(Fp, 0, seek_start);
while (idx)
{
switch (idx)
{
case 3: fread(Fp, thirdLastLine);
case 2: fread(Fp, secondLastLine);
default: fread(Fp, lastLine);
}
idx--;
}
fclose(Fp);
Re: How to read the last lines of file? -
SiJ - 27.04.2010
Quote:
Originally Posted by dice7
Well, dini saves stuff using 'keys', so just reset the keys for the last 3 reports with the correct report strings.
Btw, a method using the original file functions
pawn Code:
new File:Fp = fopen("irc_log.txt", io_read), thirdLastLine[256], secondLastLine[256], lastLine[256], idx = 0;
while (fread(Fp, lastLine) != 0) idx++; fseek(Fp, 0, seek_start);
while (idx) { switch (idx) { case 3: fread(Fp, thirdLastLine); case 2: fread(Fp, secondLastLine); default: fread(Fp, lastLine); } idx--; } fclose(Fp);
|
Oops.. My bad.. I don't use dini for that.. I also use file functions...
Thanks.. I'll try