Comparing 2 strings
#1

Код:
CMD:kill(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
if(strcmp(name,HouseInfo[79][hOwner], true)) return SendClientMessage(playerid, -1, "match");
else SendClientMessage(playerid, -1, "dont match");
return 1;
}
What am I doing wrong? I get message dont match, even though I'm sure that name matches?
Reply
#2

Код:
CMD:kill(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
if(strcmp(name,HouseInfo[79][hOwner], true) == 0) return SendClientMessage(playerid, -1, "match");
else SendClientMessage(playerid, -1, "dont match");
return 1;
}
Simple
Reply
#3

or
PHP код:
if(!strcmp(name,HouseInfo[79][hOwner], true)) return SendClientMessage(playerid, -1"match"); 
Reply
#4

It should be
Код:
if(!strcmp(name,HouseInfo[79][hOwner], true)) return SendClientMessage(playerid, -1, "match");
It will work same as
Код:
if(strcmp(name,HouseInfo[79][hOwner], true) == 0) return SendClientMessage(playerid, -1, "match");
Reply
#5

Quote:
Originally Posted by Darkwood17
Посмотреть сообщение
It should be
Код:
if(!strcmp(name,HouseInfo[79][hOwner], true)) return SendClientMessage(playerid, -1, "match");
It will work same as
Код:
if(strcmp(name,HouseInfo[79][hOwner], true) == 0) return SendClientMessage(playerid, -1, "match");
Quote:
Originally Posted by saffierr
Посмотреть сообщение
or
PHP код:
if(!strcmp(name,HouseInfo[79][hOwner], true)) return SendClientMessage(playerid, -1"match"); 
Yeah, whats wrong with mine then?
Reply
#6

But doesnt "!" mean opposite value? If so, then if(!strcmp(...) would check if strings dont match? I could be wrong
Reply
#7

Quote:
Originally Posted by Aa12
Посмотреть сообщение
But doesnt "!" mean opposite value? If so, then if(!strcmp(...) would check if strings dont match? I could be wrong
strcmp gives 0 if strings match each other on given lengths and gives 1 or -1 if strings don't match each other.

In this case, you want them to match so you should get a "0", hence why you are using !strcmp.
Reply
#8

oh ok, thanks
Reply
#9

deleted
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)