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



strcmp - AroseKhanNiazi - 12.09.2014

can some one give me good examples of strcmp i read all strcmp tutorials didn't get it working
like
if(strcmp(string1,string2))
{
//what to code here
}
else if(!strcmp(string1,string2))
{
//what to code here
}


Re: strcmp - dusk - 12.09.2014

Return values from the Wiki:
Quote:

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

So if you want to check if strings are equal:
pawn Код:
if(strcmp(string1,string2) == 0) // Which is an equivalent of if(!strcmp(string1, string2))
{
    // They are equal.
}
else // No point in using else if, not unless you care which one is first.
{
   // They are different
}
Not that if either one of them is empty, the function will say they're the same.


Re: strcmp - AroseKhanNiazi - 12.09.2014

thanks
btw i was using same from a long time (month or 2) but today it was not working i tried different ways but it didn't then i find out i was doing it with an wrong string.