[HELP]Little doubt with sscanf.
#1

Hi!
I have a little doubt with sscanf, I tried solve it by myself, but unfortunatly I couldn't.
Well, I have this:
pawn Код:
if(strcmp(x_nr,"Cuenta",true) == 0)
And I want "convert" it to sscanf, I tried something like this, but it doesn't work.
pawn Код:
if(!sscanf(params, "Cuenta", "s", opcion))
I never tried something like that in sscanf, and I don't know if it's possible make this.

NOTE: I'm using ZCMD, this is for a "/help [Option]" command.

Well, thank you all.

Best regards!
Reply
#2

What is actually supposed to do? To get data from any input string, you need to use sscanf specifiers (of which are described on the main post in the topic about sscanf).

https://sampforum.blast.hk/showthread.php?tid=120356
Reply
#3

You're not using sscanf properly.

You can't use sscanf to replace strcmp, you use it to split strings. But you only have one string, so there's no point in splitting it.

pawn Код:
CMD:help(playerid, params[]) {
   if(!strcmp(params, "Cuenta")) {
      // Your code here.
   }
   return 1;
}
The 'params' variable holds everything that's typed after the command, if there's just one thing, then you might as well just use 'params' directly, like I've done in the code example above.
Reply
#4

I thought I can do it with sscanf, hehe...
I already know use strcmp. But thank you!

Best regards!
Reply
#5

You can do it with sscanf, but it's pointless. You only have a single string. It's wise to use sscanf to split multiple variables, and you clearly didn't know about the 'params' with strcmp in zcmd.
Reply
#6

Quote:
Originally Posted by Calgon
Посмотреть сообщение
You can do it with sscanf, but it's pointless. You only have a single string. It's wise to use sscanf to split multiple variables, and you clearly didn't know about the 'params' with strcmp in zcmd.
I could make it with strcmp by myself, but I thought with sscanf it's more optimized. lol
Thanks anyway.
pawn Код:
//I know about strcmp in zcmd. ;)
COMMAND:help (playerid, params[])
{
    if(isnull(params))
    {
        //info about help options. xd
        return 1;
    }
    if(strcmp(params,"lol1",true) == 0)
    {
       //lalala
    }
    else if(strcmp(params,"lol2",true) == 0)
    {
        //lsgds
    }
    else if(strcmp(params,"lol3",true) == 0)
    {
        //aham xd
    }
    else SendClientMessage(playerid,-1,"etc... etc...");
    return 1;
}
//xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)