SA-MP Forums Archive
Help fread using sscanf - 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)
+--- Thread: Help fread using sscanf (/showthread.php?tid=547271)



Help fread using sscanf - FailerZ - 21.11.2014

Help me...
How may i read this file
Код:
50.0,SomeName
I have tried this but dosent work, can you help me to fix it
pawn Код:
CMD:read(playerid)
{
    new Float:HP, Name[MAX_PLAYER_NAME], str[250];
    new File:file = fopen("Test.txt", io_read);
    while(fread(file, str))
    {
        sscanf(str, "p<,>fs", HP, Name);
        SetPlayerName(playerid, Name);
        SetPlayerHealth(playerid, HP);
    }
    fclose(file);
    return 1;
}



Re: Help fread using sscanf - dominik523 - 21.11.2014

Try to write 50.0(space)SomeName in the file


Re: Help fread using sscanf - FailerZ - 21.11.2014

Quote:
Originally Posted by dominik523
Посмотреть сообщение
Try to write 50.0(space)SomeName in the file
Work but how to read the file when there is a ',' between them?


Re: Help fread using sscanf - dominik523 - 21.11.2014

Use this to change commas to space:
pawn Код:
// credits to whoever made this
stock split(const strsrc[], strdest[][], delimiter)
{
    new i, li;
    new aNum;
    new len;
    while(i <= strlen(strsrc))
    {
        if(strsrc[i] == delimiter || i == strlen(strsrc))
        {
            len = strmid(strdest[aNum], strsrc, li, i, 128);
            strdest[aNum][len] = 0;
            li = i+1;
            aNum++;
        }
        i++;
    }
    return 1;
}
You can save anything you want with commas and than use sscanf after this.


Re: Help fread using sscanf - Vince - 21.11.2014

Sscanf should be able to do just that. No need for unnecessary functions. You are using the plugin, right?


Re: Help fread using sscanf - dominik523 - 22.11.2014

Well, I've just gave that function just to help change commas into spaces, and yes, it's from some old RP script which used it's own system for saving houses.
Anyway, like ****** and Vince told you, just use sscanf or systems like y_ini or MySQL for saving/loading.


Re: Help fread using sscanf - dominik523 - 24.11.2014

Sorry for a late response.
So it would work like this?
pawn Код:
new string[] = "1, 2, 3, 4";
sscanf(string, "d,d,d,d", number1...):