How can I combine these to save space in the code?
Code:if (!strcmpi("exit", command))
{
return 0;
}
if (!strcmpi("x", command))
{
return 0;
}
Printable View
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;
}
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 || ..:D
easah
EDIT: wow a lot of people beat me :rolleyes:Code:if (!strcmpi("exit", command) || !strcmpi("x", command))
return 0;
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're starting to scare me, PJ :eek:
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]
only he can know:confused:
[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.Quote:
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]
wow!...:cool:
Having the ! there is no different... strcmp returns 0 when strings are equal.
It does?? LOL, so then thats my problem! I never use strcmp, but I assumed (and am confused as to why it doesn't) that if they were equal it would return true, not false! :D
My bad! <shrinks into the shadows...>