strcmp help - is string1 the same as string2
#1

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.
Reply
#2

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.
Reply
#3

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.
Reply
#4

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)
Reply
#5

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?"
Reply
#6

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.
Reply
#7

so ****** is right then, since -1 would also work his way.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)