SA-MP Forums Archive
A little help with scanf and delimiters - 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: A little help with scanf and delimiters (/showthread.php?tid=490478)



A little help with scanf and delimiters - djshadowxm81 - 26.01.2014

a little snippit of my code, i feel like im not doing this right.
Код:
if(strfind(data, "stopandhold", false) != -1)//stopandhold,dept,info,reason
{
new dept[16], info[48], reason[48];
sscanf(data,"p<,>s[16]s[48]s[48]", dept, info, reason);
//rest of code ommited
}
I am pulling csv data from a socket. But for what ever reason its not parsing all the data correctly because i suspect im not parsing the delimiters correctly. Any help here?


Re: A little help with scanf and delimiters - Scottas - 26.01.2014

pawn Код:
if(strfind(data, "stopandhold", false) != -1)//stopandhold,dept,info,reason
{
new dept[16], info[48], reason[48];
sscanf(data,"p<,>'stopandhold's[16]s[48]s[48]", dept, info, reason);
//rest of code ommited
}
Try this way


Re: A little help with scanf and delimiters - djshadowxm81 - 26.01.2014

I'll give it a shot. Thanks. I'll report back if it doesnt work.


Re: A little help with scanf and delimiters - djshadowxm81 - 26.01.2014

That worked like a champ sir! I appreciate the help on that, i've been wracking my brain at that for the past week and a half trying to get that stupid to thing to parse correctly. One other quick thing I have to ask

this isnt thru my sockets thru a zcmd processor
if(sscanf(params, "s[64]s[64]", str, reason))

for what ever reason if i type a string out with spaces for the var "Str" it automaticly wants to take the spaces and delmit it to the next variable. Any thoughts?


Re: A little help with scanf and delimiters - Scottas - 26.01.2014

using different delimiter than space would help


Re: A little help with scanf and delimiters - [ABK]Antonio - 26.01.2014

Quote:
Originally Posted by djshadowxm81
Посмотреть сообщение
a little snippit of my code, i feel like im not doing this right.
Код:
if(strfind(data, "stopandhold", false) != -1)//stopandhold,dept,info,reason
{
new dept[16], info[48], reason[48];
sscanf(data,"p<,>s[16]s[48]s[48]", dept, info, reason);
//rest of code ommited
}
I am pulling csv data from a socket. But for what ever reason its not parsing all the data correctly because i suspect im not parsing the delimiters correctly. Any help here?
You aren't accounting for "stopandhold"

which could be;

pawn Код:
sscanf(data, "p<,>{s[chars]}s[16]s[48]s[48]", dept, info, reason);