What am I doing wrong? (SSCANF, 1 line mistake) -
Pizzy - 22.08.2017
Haven't needed to ask for help in a while, but I'm stuck with 1 line of SSCANF.
Код:
new RadioID, bracket[1]; //MySQL Radio ID
sscanf(inputtext, "ds[1]", RadioID, bracket);
Basically, I've got a dialog in the format of:
1) Text here (RadioID should be = 1)
2) More text here (RadioID should be = 2)
3) Even more here (RadioID should be = 3)
55) more and more (RadioID should be = 55)
I am trying to split the number at the beginning, and put it in the variable 'RadioID'.
With the above code, The 'RadioID' shows as 0. It doesn't work.
What am I doing wrong? (I've never really understood what all the sscanf <|> etc means, so thought it'd be best to ask.)
Thanks! will +rep
Re: What am I doing wrong? (SSCANF, 1 line mistake) -
Pizzy - 22.08.2017
Bump,
Urgently need help on this.
Cheers
Re: What am I doing wrong? (SSCANF, 1 line mistake) -
Misiur - 22.08.2017
Do you mean that players put that in the input? Or do they choose it from dialog_style_list? If the latter, then you need to work with listitem. However if the user inputs this text, then this should work:
pawn Код:
sscanf(inputtext, "p<)>d", RadioID);
Re: What am I doing wrong? (SSCANF, 1 line mistake) -
Pizzy - 22.08.2017
Quote:
Originally Posted by Misiur
Do you mean that players put that in the input? Or do they choose it from dialog_style_list? If the latter, then you need to work with listitem. However if the user inputs this text, then this should work:
pawn Код:
sscanf(inputtext, "p<)>d", RadioID);
|
It's a dialog list, but it is definitely 'inputtext', as IG I made a string and it shows inputtext as = 1) Text here
Even though it's a list.
Will the code you just put up work for that? I'll try it now and test for sure.
EDIT: Works perfect. Thank you!
Re: What am I doing wrong? (SSCANF, 1 line mistake) -
Misiur - 22.08.2017
Yup, I've tested it with
pawn Код:
new a = 0;
sscanf("15) whatever", "p<)>d", a);
printf("%d", a); //15
Re: What am I doing wrong? (SSCANF, 1 line mistake) -
Pizzy - 22.08.2017
Works great. Thanks alot. I still have no idea how sscanf works, as my "logic" would have done:
"dp<)>"
instead of
"p<)>d"
Ah well. +Rep, thanks alot!
Re: What am I doing wrong? (SSCANF, 1 line mistake) -
Paulice - 23.08.2017
Quote:
Originally Posted by Pizzy
Works great. Thanks alot. I still have no idea how sscanf works, as my "logic" would have done:
"dp<)>"
instead of
"p<)>d"
Ah well. +Rep, thanks alot!
|
sscanf = text processor
specifier "p" = split
<)> = where ")" is found
d (could also be "i") = "data type" of variable passed by reference
p<delimiter>"data type(s)" = syntax of specifier "p"
Re: What am I doing wrong? (SSCANF, 1 line mistake) -
10MIN - 23.08.2017
Read this
tutorial about sscanf.