Bug with strcmp?
#8

Lorenc_'s solution will be the best, but sscanf is not needed:
pawn Код:
CMD:anim(playerid, params[])
{
  new aStr[32]

  // All animations in one command.
  if(isnull(params)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /anim [animation]");
 
  if      (strcmp("rsmg", aStr, true) == 0 || strcmp("rm4", aStr, true) == 0 || strcmp("rak", aStr, true) == 0) OnePlayAnim(playerid, "UZI", "UZI_reload", 4.0, 0, 0, 0, 0, 0);
  else if (strcmp("rdeagle", aStr, true) == 0) OnePlayAnim(playerid, "COLT45", "colt45_reload", 4.0, 0, 0, 0, 0, 1);
  else if (strcmp("carjacked1", aStr, true) == 0) LoopingAnim(playerid, "PED", "CAR_jackedLHS", 4.0, 0, 1, 1, 1, 0);
  else if (strcmp("carjacked2", aStr, true) == 0) LoopingAnim(playerid, "PED", "CAR_jackedRHS", 4.0, 0, 1, 1, 1, 0);
  else SendClientMessage(playerid, COLOR_WHITE, "USAGE: /anim [animation]");
  return 1;
}
strcmp is not designed to comp are if two string completely matches (since it also returns 1 or -1 depends on the string length).
Also, if you do this:
pawn Код:
strcmp("", "asdasd", true)
it will always return 0.

You may try my strcmpex function, which don't have such problems, and it is slightly faster in case insensitive checks:
pawn Код:
stock strcmpex(const string1[],const string2[],bool:ignorecase = false,length = cellmax)
{
    if(!isnull(string1) && !isnull(string2))
    {
        new len1 = strlen(string1),len2 = strlen(string2);
        if(len1 == len2 || length != cellmax)
        {
            if(length > len1) length = len1;
            if(!ignorecase)
            {
                for(new i = 0;i < length;i++)
                    if(string1[i] != string2[i]) return 1;
            }
            else
            {
                for(new i = 0;i < length;i++)
                    if(string1[i] != string2[i])
                    {
                        switch(string1[i])
                        {
                            case 'A'..'Z','a'..'z':
                            {
                                switch(string2[i])
                                {
                                    case 'A'..'Z','a'..'z': if((string1[i] | 0x20) != (string2[i] | 0x20)) return 1;
                                    default: return 1;
                                }
                            }
                            default: return 1;
                        }
                    }
            }
            return 0;
        }
    }
    else if(isnull(string1) && isnull(string2)) return 0;
    return 1;
}

#if defined strcmp
    #undef strcmp
#endif
#define strcmp strcmpex
Reply


Messages In This Thread
Bug with strcmp? - by GrimR - 29.09.2011, 02:36
Re: Bug with strcmp? - by Lorenc_ - 29.09.2011, 03:58
Re: Bug with strcmp? - by GrimR - 29.09.2011, 04:17
Re: Bug with strcmp? - by $India$ - 29.09.2011, 04:55
Re: Bug with strcmp? - by Lorenc_ - 29.09.2011, 05:05
Re: Bug with strcmp? - by $India$ - 29.09.2011, 05:13
Re: Bug with strcmp? - by GrimR - 29.09.2011, 08:39
Re: Bug with strcmp? - by leong124 - 29.09.2011, 08:56
Re: Bug with strcmp? - by GrimR - 29.09.2011, 10:35
Re: Bug with strcmp? - by Jochemd - 29.09.2011, 14:51

Forum Jump:


Users browsing this thread: 2 Guest(s)