difference for !strcmp and strcmp?

Recommended Posts

In the tutorial doc use this example !strcmp I was thinking that is Logical NOT, but isn't. Someone can explain this to me?

```if(!strcmp(%userName, "Heather"))
else

From the Tscript reference use this example. What is the difference?

```if( strcmp( %var, "foobar" ) == 0 )
echo( "%var is equal to 'foobar'" );```
Share on other sites

both are equivalent. !strcmp is the same thing as strcmp == 0. When the strings are equal, it returns 0.

Share on other sites

! is the boolean negation operator (it means not). !0==1 and !1==0 (and, IIRC, !2==0, !#==0, etc.). strcmp returns 0 if the two strings are equal, so !strcmp will return 1 if they're equal (or 0 if they're not equal).

Share on other sites

Is this correct?

```// Testing 1
function matchNum1(%numBer)
{
if(strcmp(%numBer, "0"))
echo("Number 0 Found.");
else if(strcmp(%numBer, "1"))
echo("Number 1 Found.");
else
}```

Output:

```matchNum1(0);
Number 1 Found
matchNum1(1);
Number 0 Found```

```// Testing 2
function matchNum2(%numBer)
{
if(!strcmp(%numBer, "0"))
echo("Number 0 Found.");
else if(!strcmp(%numBer, "1"))
echo("Number 1 Found.");
else
}```

Output:

```matchNum2(0);
Number 0 Found
matchNum1(1);
Number 1 Found```

Share on other sites

hahaha so sorry mate :lol: I was a little tired that day :oops: I use my free time to learn t3d...

Share on other sites

Hey, people gotta learn what strcmp is/does at some point in time. It's no biggie.

Also, in TS, there's a string comparitor operator

```if(%myString \$= "ThingIWantToCheck")
return "woo";
if(%myString !\$= "ThingIWantToCheck")
return "boo";
```

If you know you're dealing with strings, it can be a bit easier to just use that instead of using the strcmp function.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×

• Games

• Discord
×
• Create New...