Ignoring spaces (strcmp)
#1

When i use:
pawn Код:
if(strcmp(params, "help", true) == 0)
{
  // code
}
And i type "help " (with a spaces) strcmp returns true and the command doesn't work. How can i make it ignore spaces?
Reply
#2

Just use strfind to find help.
Reply
#3

That will work even if the string is "helpme" or "helpsdhsk", won't that?
Reply
#4

Try to use strtok, or something. Or make your own function... I don' t know
Reply
#5

Quote:
Originally Posted by SAWC™
That will work even if the string is "helpme" or "helpsdhsk", won't that?
Yeah, it will. You will have to make your own function for that.
Reply
#6

Something like, but maybe not exactly this:

pawn Код:
new idx, tmp [ 256 ];

tmp = strtok ( params , idx );

if ( strcmp ( tmp , "help" , true ) == 0 )
{
  // Your Code Here
}
Untested so sorry if theres any mistakes. It should give you an idea of what to do even if doesnt work.

NOTE: This works assuming the "help" is at the start of your message. If it is in the middle or end etc you will need strfind
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)