Last 10 .txt
#1

Hello,
i have one thing to do but i not know how.Okay...
1.What i need to do?
-I need to get last 10 lines from one .txt file.
2.How much lines have in that .txt file?
- They are dynamic ca be 10 or 10000.
3.For what i need to do that?
- I work on one report system witch saves all reports in one .txt file.
4.Any special thing for that?
- I need to make one command /lastreports or something like that and to show last 10 reports from all users.
They do /report nanana... 10 times i need to get 10 times nanana..About the name of .txt i can change it just give sample with report.txt

Thanks for help all are wellcome.

Hello its me again :P,
Okay i made one command but i have something like error.
1.What kind of error?
-Okay in pawn everything is good no error no warning.But in game i write the command /lastreports and nothing happens 30 seconds after i write the command server shutting down.
2.Where is the command?
-
pawn Код:
if(strcmp(cmd, "/lastreports", true) == 0)
    {
      new lines;
      new File:zeport = fopen("/Log/zeport.log", io_read);
        while(fread(zeport, str))////..
        {
        lines++;
        }
        printf("File has %d lines");

        new max_lines = lines;
        lines = 0;
        while(lines < max_lines - 10)
        {
          fread(zeport, str); //moving the pointer a line down until its on the 10th line from the back
          lines++;
        }
        while(max_lines >= lines)
        {
          fread(zeport, str); //reading the last 10 lines
          format(str, sizeof(string), "Last 10 reports: %d", lines);
          SendClientMessage(playerid, COLOR_RED, str);
          printf("Reading line %d", lines);
          lines++;
        }
        fclose(zeport);
        return 1;
    }

3.What you want to do?
- Just look for errors because i thing have some...
Reply
#2

pawn Код:
new lines;
while(fread(string, FILE))
{
  lines++;
}
printf("File has %d lines", lines);

new max_lines = lines;
lines = 0;
while(lines < max_lines - 10)
{
  fread(string, FILE); //moving the pointer a line down until its on the 10th line from the back
  lines++;
}

while(max_lines >= lines)
{
  fread(string, FILE); //reading the last 10 lines
  printf("Reading line %d", lines);
  lines++;
}
Reply
#3

Thanks very much im going to test that now.
Reply
#4

Any one can help please i need that
Reply
#5

yea me to need that i like it help
Reply
#6

Can any one find a error here , because not work in my server. Please help.
Reply
#7

Try fseek, because you need to return to the beginning of the file.

pawn Код:
if(strcmp(cmd, "/lastreports", true) == 0)
    {
        new lines;
        new File:zeport = fopen("/Log/zeport.log", io_read);
        while(fread(zeport, str))////..
        {
            lines++;
        }
        printf("File has %d lines", lines);
       
        new max_lines = lines;
        lines = 0;
        fseek(zeport, 0);
        while(lines < max_lines - 10)
        {
            fread(zeport, str); //moving the pointer a line down until its on the 10th line from the back
            lines++;
        }
        while(max_lines >= lines)
        {
            fread(zeport, str); //reading the last 10 lines
            format(str, sizeof(string), "Last 10 reports: %d", lines);
            SendClientMessage(playerid, COLOR_RED, str);
            printf("Reading line %d", lines);
            lines++;
        }
        fclose(zeport);
        return 1;
    }
Reply
#8

Again not work agrhhhh... Thanks for try to help me but try again please
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)