io read/write - 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: io read/write (
/showthread.php?tid=252866)
io read/write -
DRIFT_HUNTER - 03.05.2011
Sup everyone long time didnt asked ass question's but here is one:
I have no clue how fread and write works so i asking you how i can make small thing
I want to make my own BAN system so i need to save bans in format something like...
USER_NAME|USER_IP|TIME_&_DATE|HOST
And "|" will be used as delimiter to format line later
So how i can save and load these?
Pls some give me some examples so i can see how its working. Thx
Re: io read/write -
miokie - 03.05.2011
I was just testing this out a few days ago using commands to read and write using Sscanf, Here's my code I used to test with if it could be of any help:
Write
pawn Код:
new v1,v2,str[20],string[128];
if (sscanf(params, "sii", str,v1,v2)) return SendClientMessage(playerid, 0xEFEFF7AA, "* USAGE: /Savetest [Name] [Value] [Value] ");
new File:pos=fopen("Testing.txt", io_append);
format(string, 256, "%s %i %i\r\n",str,v1,v2);
SendClientMessage(playerid,0xEFEFF7AA,string);
fwrite(pos, string);
fclose(pos);
Read
pawn Код:
new str[20], str2[50];
new name[20], v1,v2;
new string[256];
if (sscanf(params, "s", str)) return SendClientMessage(playerid, 0xEFEFF7AA, "* USAGE: /Loadtest [Name]");
new File:pos=fopen("Testing.txt", io_read);
while(fread(pos, str2))
{
if(!sscanf(str2, "sii", name,v1,v2))
if(!strcmp(name,str,true))
{
format(string, 256, "[FOUND] Name: %s | Values: %i and %i",str,v1,v2);
SendClientMessage(playerid,0xEFEFF7AA,string);
break;
}
}
fclose(pos);
(It searches for the line that starts with the word written into the command param.)
Re: io read/write -
DRIFT_HUNTER - 03.05.2011
Thx man