strcmp help - is string1 the same as string2 -
Jack_Leslie - 12.09.2011
Hi guys. I tried using this page as help:
https://sampwiki.blast.hk/wiki/Strcmp
For this code:
Код:
if(!strcmp(BizInfo[PlayerInfo[playerid][pBizKey]][bOwner],PlayerName(playerid),true))
But I still can't get it to work. It's meant to ask if string1 IS NOT the same as string2, then proceed with the code below. But it won't work.
Re: strcmp help - is string1 the same as string2 -
PrawkC - 12.09.2011
change
if(!strcmp(BizInfo[PlayerInfo[playerid][pBizKey]][bOwner],PlayerName(playerid),true))
to
if(strcmp(BizInfo[PlayerInfo[playerid][pBizKey]][bOwner],PlayerName(playerid),true))
... it returns 0 if the string matches, thus by having the "!" its checking if the string matches.
Re: strcmp help - is string1 the same as string2 -
Jack_Leslie - 12.09.2011
Quote:
Originally Posted by PrawkC
change
if(!strcmp(BizInfo[PlayerInfo[playerid][pBizKey]][bOwner],PlayerName(playerid),true))
to
if(strcmp(BizInfo[PlayerInfo[playerid][pBizKey]][bOwner],PlayerName(playerid),true))
... it returns 0 if the string matches, thus by having the "!" its checking if the string matches.
|
Oh yeah, course, that worked, thanks.
Re: strcmp help - is string1 the same as string2 -
Blacklite - 12.09.2011
strcmp can return values less than 0 too. To correctly check if string1 does not match string2, use this:
pawn Код:
if(strcmp(BizInfo[PlayerInfo[playerid][pBizKey]][bOwner],PlayerName(playerid),true) != 0)
Re: strcmp help - is string1 the same as string2 -
cessil - 12.09.2011
if you imagine strcmp as plain text then it'd be "can i compare these two strings?" and then it's easier to imagine no i can't compare them because they're the same.
It seems a quite a few people when they start out think of it as "are these two strings the same?"
Re: strcmp help - is string1 the same as string2 -
xDeadlyBoy - 12.09.2011
Quote:
Originally Posted by Blacklite
strcmp can return values less than 0 too. To correctly check if string1 does not match string2, use this:
pawn Код:
if(strcmp(BizInfo[PlayerInfo[playerid][pBizKey]][bOwner],PlayerName(playerid),true) != 0)
|
when you don't use a condition it's check if the result is
different than 0, not more.
Re: strcmp help - is string1 the same as string2 -
cessil - 12.09.2011
so ****** is right then, since -1 would also work his way.