File Reading
#1

How to get last 4 lines of a file?

forexample i have this data in the file:

Код:
1
2
3
4
5
How to get the last 4 lines of that file?
Reply
#2

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
Reply
#3

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

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

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)