SA-MP Forums Archive
Comparing 2 strings - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Comparing 2 strings (/showthread.php?tid=598014)



Comparing 2 strings - Aa12 - 07.01.2016

Код:
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?


Re: Comparing 2 strings - Darkwood17 - 07.01.2016

Код:
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


Re: Comparing 2 strings - saffierr - 07.01.2016

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



Re: Comparing 2 strings - Darkwood17 - 07.01.2016

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");



Re: Comparing 2 strings - saffierr - 07.01.2016

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?


Re: Comparing 2 strings - Aa12 - 08.01.2016

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


Re: Comparing 2 strings - Rufio - 08.01.2016

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.


Re: Comparing 2 strings - Aa12 - 08.01.2016

oh ok, thanks


Re: Comparing 2 strings - Aa12 - 08.01.2016

deleted