Regarding sscanf
#1

I've noticed that with sscanf, if you put a string before an interger or even another array...

pawn Код:
if(sscanf(params, "s[123]ddd", string, var1, var2, var3)) return sendclien...(playerid, color, "usage: /bla [string] [var1] [var2] [var3]);
The problem is that, if the "string" contains any spaces at all, it basically tells you to go fuck yourself, and counts the space as a change to the next variable (?).

Is there any way to fix this without putting the strings at the end of the command (if that would even work..?)
Reply
#2

hmm interesting i thing you would have to make a bit of code to manualy check it and replace the ' ' in the sting with another character as long as there is not a number after it then sscanf it then if you want you print the string you would need to change the character you inserted back to a ' ' so it read to the player as it was entered

hmm i kinda wanna try this now sounds like a fun little project really just a work around though

edit: and reading the sscanf command looks like putting it at the end would only return 1 word too
Reply
#3

Lol have fun, any other suggestions on how to make this work?
Reply
#4

rewrite sscanf lol
i think ill have a go tomorrow i dont think my first suggestion would be to bad but we will see
Reply
#5

Use - instead of space in the string?
Reply
#6

Sscanf(params[1],"p<\">s[32]p< >dd");

This would make the player have to type
/MyCommand "my string" 1 2
Reply
#7

Well wouldn't the space after "my string" force a parameter change? Which would make the 1 in "/MyCommand "My String" 1 2" be the 2nd parameter and not the 1st. I say this because both the double quote and the space are delimiters and they're right next to each other.

So my revised code would be

pawn Код:
if(sscanf(params[1],"p<\">s[32]p< > dd",string,var1,var2) || (params[0]!='\"'))//erroneous code
//  /MyCommand "My String" 1 2
using the space between 'p< >' and 'dd' as a way to skip the expected space
Reply
#8

Код:
if(sscanf(params, "ddds[123]", var1, var2, var3,string)) return sendclien...(playerid, color, "usage: /bla [var1] [var2] [var3] [string]);
Stick string at the end instead, problem solved.
Reply
#9

Alright thanks everybody for the replies. I'll take the easy route and stick the string at the end.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)