sscanf problem - 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: sscanf problem (
/showthread.php?tid=363305)
sscanf problem -
Killer#Mummy - 27.07.2012
Hello! My deathmatch did not work, so I looked in my code.
pawn Код:
stock Load_Deathmatch(MapNumber)
{
new Count,Data[128];
new File: File = fopen("blabla//Deathmatch.txt",io_read);
while(fread(File,Data,sizeof(Data)))
{
if(!sscanf(Data,"p<|>dddd",Map[MapNumber][mDeathmatch_Mode],Map[MapNumber][mDeathmatch_Money],Map[MapNumber][mDeathmatch_Score],Map[MapNumber][mDeathmatch_Time]))
{
// 1|5000|3|3
Count = Count + 1;
Count = Count - 1;
//It is not working without these two 'useless' lines
}
else
{
if(!sscanf(Data,"p<|>dd",Map[MapNumber][mDeathmatch_Weapon_Model][Count],Map[MapNumber][mDeathmatch_Weapon_Ammo][Count]))
{
// 32,400
Count++;
}
else
{
Map[MapNumber][mError] = TRUE;
fclose(File);
return 0;
}
}
} fclose(File);
return 1;
}
Deathmatch.txt file looks like this:
Код:
0|2000|3|2
22|20
25|19
18|18
33|17
34|16
The problem is, that sscanf 'thinks' that p<|>dddd can be also used for othes lines in Deathmatch.txt and not just for first one. How can I modify sscanf statement, so p<|>dddd load first line in file and p<|>dd loads the others?
Thanks.
Re: sscanf problem -
Killer#Mummy - 28.07.2012
Bump, please, how can I fix this? Is there any sscanf parameter to fix this?
Re: sscanf problem -
ReneG - 28.07.2012
The optional specifier? D instead of d.
Re: sscanf problem -
Killer#Mummy - 28.07.2012
Hmm, I think that I don't need optional D. The point is, that if the readed line from file doesn't include 4 integers, it must check if the readed line includes 2 integers, but somehow the script think that '26|33' are four integers. Sorry my awful english but I'm trying at my best.
Little pseudo code of what I mean:
Код:
if(!sscanf(Data,"p<|>dddd",num1,num2,num3,num4))
{
//this will execute if the Data includes 4 integers
}
else
{
//this will execute if the Data does NOT include 4 integers
if(!sscanf(Data,"p<|>dd",num5,num6))
{
//this will execute if the Data includes 2 integers
}
else
{
//this will execure if the Data does NOT include 4 OR 2 integers
}
}
Somehow my code is not working
. Help, please?