How to Compare if 2 strings are NOT equal?
#1

Ok, i want that if the string DOESN'T match, it should send this message, but with this code, it will send the message if the string matches right? Any idea how do i check about inequality with strcmp?

Код:
if(!strcmp(Faction_GetName(playerid), "S.W.A.T", true, 5))
	    return SendErrorMessage(playerid, "You're not S.W.A.T Member");
Reply
#2

Returns 0 if they're equal so check if it's not 0:
pawn Код:
if(strcmp(Faction_GetName(playerid), "S.W.A.T", true))
pawn Код:
if(strcmp(Faction_GetName(playerid), "S.W.A.T", true) != 0)
Reply
#3

strcmp returns values other than 0 if they're not equal. So you can simply remove "!" from your strcmp's if statement or do as follow :
pawn Код:
if(strcmp(string, string2, true) != 0) {
    //not equal.
}
EDIT : Late.
Reply
#4

Thanks a lot!

Edit: This shows tag mismatch warning?

Код:
if(!strcmp(Faction_GetName(playerid), "S.W.A.T", true) != 0)
	    return SendErrorMessage(playerid, "You are not a S.W.A.T Member");
Reply
#5

It also doesn't work anymore the way it should. Works Vice-Versa.
Reply
#6

Quote:
Originally Posted by [ND]xXZeusXx.
Посмотреть сообщение
Thanks a lot!

Edit: This shows tag mismatch warning?

Код:
if(!strcmp(Faction_GetName(playerid), "S.W.A.T", true) != 0)
	    return SendErrorMessage(playerid, "You are not a S.W.A.T Member");
You can't use ! before strcmp and != 0 at the same time. Re-read the posts above.
Reply
#7

Sorry, My bad.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)