mardi 10 février 2015

Two If statements execute at once, instead of one

I've got a program that takes input from a char Array, using the strtok function to check if the input contains the words "up" or "down". If it contains the word "up", my b value is set false (i.e b = 0) and my c value is set to false as well. If the char array contains the words "down", b is set to false, however my c value is set to true (i.e c= 1).


My problem occurs when the word "up" are contained in the string, as the first if statement executes, and prints the resultant characters on the screen, but somehow the second if also executes printing those characters as well. Any input on this matter would be much appreciated


EDIT: The same problem occurs if I use the word "down", both if statements are executed.



int moveC(int y, int x, int b, int i, int c) {
// int c is a static variable(static int c = FALSE;) defined in the previous function
int j;
int k;

switch (b) //assume b is always false (which it is)
{
case FALSE:
if (c == 0) {
mvprintw(y, x, "^");
refresh();

for (j = 1; j <= i; j++) {
mvprintw(y + j, x, ".");
refresh();
}
break;
}

if (c == 1) //tried using else if, same result
{

mvprintw(y, x, "^");
refresh();

for (j = 1; j <= i; j++) {
mvprintw(y - j, x, ".");
refresh();
}
break;
}
}
return 0;
}

Aucun commentaire:

Enregistrer un commentaire