io read/write
#1

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

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

Thx man
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)