Help fread using sscanf
#1

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

Try to write 50.0(space)SomeName in the file
Reply
#3

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?
Reply
#4

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.
Reply
#5

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

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

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...):
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)