What am I doing wrong? (SSCANF, 1 line mistake)
#1

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

Bump,

Urgently need help on this.

Cheers
Reply
#3

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);
Reply
#4

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

Yup, I've tested it with
pawn Код:
new a = 0;
sscanf("15) whatever", "p<)>d", a);
printf("%d", a); //15
Reply
#6

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

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"
Reply
#8

Read this tutorial about sscanf.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)