Scanning chars, ints, doubles and char arrays
So i have a program that asks the user a command (a letter) to run a specific method, it can be just the letter, a letter and some numbers, or a letter and another word, right now i have this:
Code:
char com;
char col [6];
char name [MAXELEMENTS];
int a, b;
double c;
while(scanf(" %c", &com) == 1 && com != 'q'){
if(com == 'p'){
list(matrix);
}
else if(com == 'a'){
scanf("%d %d %lf", &a, &b, &c);
adds(a, b, c, matrix);
}
else if(com == 'i'){
carac(matrix);
}
else if(com == 'l'){
scanf("%d", &a);
printLine(a, matrix);
}
else if(com == 'c'){
scanf("%d", &a);
printColumn(a, matrix);
}
else if(com == 'z'){
scanf("%lf", &c);
zero(c, matrix);
}
else if(com == 'o'){
if((scanf("%s", col)) == 1)
sortColumn(matrix);
else if((scanf("%s", col)) == 0)
sortLine(matrix);
}
else if(com == 'w'){
if((scanf("%s", name)) == 1)
ficheiro(name, matrix);
else if((scanf("%s", name)) == 0)
ficheiroNovo(matrix);
}
}
So iīm having trouble in the commands "o" and "w". On "o" you are supposed to have the option to just type "o" and it should run the method sortLine or you type the "o column" and it runs sortColumn. On "w" the same concept, you just type "w" and it runs ficheiroNovo or you type "w" plus a name and it should run ficheiro. The thing is i canīt just type "o" or "w", it always asks for another input and always runs the sortColumn or ficheiro. Does anyone know whatīs wrong anc can someone help me?