PDA

View Full Version : what is the difference?

Don_Cage
18/05/2013, 03:39 AM
Some people does like thisif(strcmp(cmd, "/cmd", true) == 0)
and some people do like this if(!strcmp(cmd, "/cmd", true) == 0)
what is the difference between putting the '!' and not doing it in just that place?

EDIT: and also what is the '== 0' about? I mean you can still make exact cmd without the '== 0'

SchurmanCQC
18/05/2013, 04:02 AM
If the '!' is present, you do not need '== 0'. I believe having both is a double negative (https://en.wikipedia.org/wiki/Double_negative).

! means either 0 or false.
When ! is not present, it means equal to 1 or true.

You can void both of the above by including '== (VALUE)'

Don_Cage
18/05/2013, 04:10 AM
So i must either do if(!strcmp(cmd,"/cmd",true))
or if(strcmp(cmd,"/cmd",true) == 0)
or can i do if(strcmp(cmd,"/cmd",true)) and remove both?

SchurmanCQC
18/05/2013, 04:15 AM
So i must either do if(!strcmp(cmd,"/cmd",true))
or if(strcmp(cmd,"/cmd",true) == 0)
or can i do if(strcmp(cmd,"/cmd",true)) and remove both?

You can use the first or second.

The third will see if the string is not equal, so it will execute if you type anything except /cmd.

This all depends on what strcmp returns.

STRCMP returns false or 0 if the string is equal or one is empty.

STRCMP returns true or 1 if string 1 comes after string 2
STRCMP returns -1 if string 2 comes after string 1

Don_Cage
18/05/2013, 04:46 AM
Ok, well that awnsered my question. Thank you