Last 10 .txt - 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: Last 10 .txt (
/showthread.php?tid=121967)
Last 10 .txt -
gecatahh - 19.01.2010
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...
Re: Last 10 .txt -
dice7 - 19.01.2010
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++;
}
Re: Last 10 .txt -
gecatahh - 19.01.2010
Thanks very much im going to test that now.
Re: Last 10 .txt -
gecatahh - 19.01.2010
Any one can help please i need that
Re: Last 10 .txt -
FakerBG - 19.01.2010
yea me to need that i like it help
Re: Last 10 .txt -
gecatahh - 21.01.2010
Can any one find a error here , because not work in my server. Please help.
Re: Last 10 .txt -
MadeMan - 21.01.2010
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;
}
Re: Last 10 .txt -
gecatahh - 21.01.2010
Again not work agrhhhh... Thanks for try to help me but try again please