SA-MP Forums Archive
Need help regarding 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: Need help regarding strcmp. (/showthread.php?tid=509807)



Need help regarding strcmp. - rangerxxll - 28.04.2014

I don't really need help, I just have a question really. I attempted to create a simple dialog that will create a pickup if "pickup" is entered as inputtext. The first time I did it, it was this:

pawn Код:
if(strcmp("pickup", inputtext, true))
I tested it in-game and it didn't work. So I added a ! just for the hell of it (Which I assumed means "Doesn't" or "Not"). It seemed to work after this was added.

Anywho, I tried reading it and to me it says "If string compaired is not... blah blah." Why is ! neccessary when compairing strings?


Re: Need help regarding strcmp. - Corekt - 28.04.2014

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

Quote:
Return Values:
-1 if string1 comes before string2
1 if string1 comes after string2
0 if the strings are the same (for the matched length).

As for why returning 0 means the strings are equal, the two strings are compared in lexicographic (alphabetical) order.

So there can be 3 possibilities: the 1st string comes before the 2nd string in a dictionary, both are equal, or the 1st string comes after the 2nd string. To me it would make more symmetric sense to return the values -1, 0, 1 rather than 0, 1, 2.


Re: Need help regarding strcmp. - RajatPawar - 28.04.2014

I know this has been already answered above, but for simplicity's sake -

Matched strings return 0. ! (0) returns a true condition. That's why..