SA-MP Forums Archive
The Difference Between !strcmp & strcmp - 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: The Difference Between !strcmp & strcmp (/showthread.php?tid=393095)



The Difference Between !strcmp & strcmp - Dennis_Smith - 17.11.2012

I've spent time figuring out why my function didn't work. After trying !strcmp instead of strcmp, it worked. I'm clueless to why though. If someone could explain the difference to me, I'd really appreciate it.


Re: The Difference Between !strcmp & strcmp - Jefff - 17.11.2012

https://sampwiki.blast.hk/wiki/Strcmp


Re: The Difference Between !strcmp & strcmp - Dennis_Smith - 17.11.2012

Quote:
Originally Posted by Jefff
View Post
That doesn't explain anything about the explanation point.


Re: The Difference Between !strcmp & strcmp - [NRG]Dark - 17.11.2012

Strcmp

Compares two strings to see if they are the same.

Parameters:

(const string1[], const string2[], bool:ignorecase, length)

string1 The first string to compare.
string2 The second string to compare.
ignorecase (optional) When set to true, the case doesn't matter - HeLLo is the same as Hello. When false, they're not the same.
length (optional) When this length is set, the first x chars will be compared - doing "Hello" and "Hell No" with a length of 4 will say it's the same string.

Returns -1 if string1 comes before string2
1 if string1 comes after string2
0 if the strings are the same (for the matched length).




when you use !strcmp, in fact you are checking if the sentence return 0(if the strings are the same)

Sorry possibles errors in English because i don't speak english very good


Re: The Difference Between !strcmp & strcmp - SuperViper - 17.11.2012

Strcmp returns 0 when the strings match and 1 when the strings don't match. When you check a statement with !, you're checking if it returns 0, otherwise you're checking if it doesn't return 0.

pawn Code:
if(something())
is a check for the function something() returning something other than 0.

pawn Code:
if(!something())
is a check for the function something() returning 0.


If you're confused by the way strcmp works, use this macro:

pawn Code:
#define strsame(%0,%1,%2) (!strcmp(%0, %1, %2))
pawn Code:
if(strsame("Hello", "hello", true))
{
}