How can I combine these to save space in the code?
Code:if (!strcmpi("exit", command)) { return 0; } if (!strcmpi("x", command)) { return 0; }
How can I combine these to save space in the code?
Code:if (!strcmpi("exit", command)) { return 0; } if (!strcmpi("x", command)) { return 0; }
Code:if (!strcmpi("exit", command) || !strcmpi("x", command)) { return 0; }
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
if (!strcmpi("exit", command)&&(!strcmpi("x", command)))
{
return 0;
}
btw isnt it strcmp...?
Code:if (!strcmpi("exit", command) && !strcmpi("x", command) ) { return 0; }
sorry i also meant || ..
easah
EDIT: wow a lot of people beat meCode:if (!strcmpi("exit", command) || !strcmpi("x", command)) return 0;
I am against the teaching of evolution in schools. I am also against widespread
literacy and the refrigeration of food.
No, it should be &&, you had it right the first time. If it is || then it will ALWAYS return zero since the only way that statement is false is if the string is equal to both "x" and "exit" at the same time.
pj, rethink this one. look at his original code. In your example, both must be true;
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
You're starting to scare me, PJ
I am against the teaching of evolution in schools. I am also against widespread
literacy and the refrigeration of food.
he didnt meant that u must check both x and exit did he?
if not he should use ||
Wait, what exactly is he trying to accomplish? Does he want the function to continue unless the user inputs something other than "exit" or "x" or does he want it to return no matter what the user prints? Because if you use the || sign, then no matter what command is, whether it be "dog","exit" or "x" it will return. If thats the case, then why even have the if statement?
I guess I'm assuming that he means to check to see if the string isn't either "x" or "exit" which would need the &&.
[edit]
Maybe he didn't mean to use the ! operator?
[/edit]
Last edited by PJYelton; 02-04-2003 at 03:58 PM.
only he can know
[code]
if (!strcmpi("exit", command) || !strcmpi("x", command))
{
return 0;
}
[code]
thats what i wanted
Say it outloud; If string equals exit and string equals x... doesn't make sense.Originally posted by PJYelton
Wait, what exactly is he trying to accomplish? Does he want the function to continue unless the user inputs something other than "exit" or "x" or does he want it to return no matter what the user prints? Because if you use the || sign, then no matter what command is, whether it be "dog","exit" or "x" it will return. If thats the case, then why even have the if statement?
I guess I'm assuming that he means to check to see if the string isn't either "x" or "exit" which would need the &&.
[edit]
Maybe he didn't mean to use the ! operator?
[/edit]
If string equals exit or string equals x... makes sense.
I know, but aren't you forgetting about the ! operator?
if (!(x==y) || !(x==z)) will ALWAYS return true.
if (!(x==y) && !(x==z)) will return false if x is neither y or z.
[edit] Oops, the first statement I guess can return false, but only if y==z [/edit]
Last edited by PJYelton; 02-04-2003 at 04:14 PM.