How to read the last lines of file?
#1

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 ?
Reply
#2

Reply
#3

I don't know, but I don't think showing only the 3 last reports is possible.
Reply
#4

Oh well.. If it's not possible, I'll try to find another way..
Reply
#5

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);
Reply
#6

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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)