io read/write
#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


Messages In This Thread
io read/write - by DRIFT_HUNTER - 03.05.2011, 15:10
Re: io read/write - by miokie - 03.05.2011, 15:36
Re: io read/write - by DRIFT_HUNTER - 03.05.2011, 16:52

Forum Jump:


Users browsing this thread: 1 Guest(s)