Help fread using sscanf -
FailerZ - 21.11.2014
Help me...
How may i read this file
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...):