strcmp
#1

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

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

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


Forum Jump:


Users browsing this thread: 2 Guest(s)