Need help regarding strcmp.
#1

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?
Reply
#2

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.
Reply
#3

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..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)