Posts: 596
Threads: 75
Joined: Nov 2015
How to get last 4 lines of a file?
forexample i have this data in the file:
How to get the last 4 lines of that file?
Posts: 2,593
Threads: 34
Joined: Dec 2007
Open file then read whole + count lines, next use fseek(handle, 0, seek_start); and read again whole file and if counter >= idx - 4 show line for player ;d
Posts: 596
Threads: 75
Joined: Nov 2015
Quote:
Originally Posted by Jefff
Open file then read whole + count lines, next use fseek(handle, 0, seek_start); and read again whole file and if counter >= idx - 4 show line for player ;d
|
Can you please give a simple code example?
Posts: 2,593
Threads: 34
Joined: Dec 2007
pawn Код:
new str[128],lines,idx;
new File:F = fopen("file.txt",io_read);
while(fread(F, str))
lines++;
if(lines > 3)
{
fseek(F, 0);
while(fread(F, str))
{
if(++idx > lines-4)
print(str);
}
}
fclose(F);
Posts: 596
Threads: 75
Joined: Nov 2015
Quote:
Originally Posted by Jefff
pawn Код:
new str[128],lines,idx; new File:F = fopen("file.txt",io_read); while(fread(F, str)) lines++;
if(lines > 3) { fseek(F, 0, seek_start);
while(fread(F, str)) { if(++idx > lines-4) print(str); } } fclose(F);
|
Thanks
And ofc +Rep