I have a program that requires asking for user input on what to do. For example I have a function
Code:
add(int id, char name [8000],int dep)
and the user must type 'add 1 "Name1" 20´' to run this function.
I also some other methods like or .
My first problem is in the add function, as you see in the example the name has to be between " ", if not the command is not valid, I'm having a really hard time figuring out how to check this. The other functions, duration and depend are easier, you only have to type 'duration 2' for example, and 'depend'.
I'm having problems on which scanning funtion is the best, is it scanf, fgets or getChar?
I have this from a previous work using fgets but I don't know if it works well in this particular situation:
Code:
char input[90], col [6], na [80];
unsigned long a, b;
while(strcmp(input[0], "exit") != 0){
if(fgets(input, sizeof(input), stdin)){
if(input[0] == 'p' && input[1] == '\n' && input[2] == '\0'){
list(matrix);
}
else if(input[0] == 'i' && input[1] == '\n' && input[2] == '\0'){
carac(matrix);
}
else if((sscanf(input, "%c %lu %lu %lf\n", &input[0],
&a, &b ,&c) == 4)){
adds(a, b, c, matrix);
}
else if(input[0] == 'l' && (sscanf(input, "%*c %lu\n", &a) == 1)){
printLine(a , matrix);
}
else if(input[0] == 'c' && (sscanf(input, "%*c %lu\n", &a) == 1)){
printColumn(a , matrix);
}
else if(input[0] == 'z' && (sscanf(input, "%*c %lf\n", &c) == 1)){
zero(c , matrix);
}
else if(input[0] == 'o' && input[1] == '\n' && input[2] == '\0'){
sortLine(matrix);
}
else if(input[0] == 'o' && (sscanf(input, "%*c %s\n", col) == 1) && strcmp(col, "column") == 0){
sortColumn(matrix);
}
else if(input[0] == 'w' && input[1] == '\n' && input[2] == '\0'){
file(matrix);
}
else if(input[0] == 'w' && (sscanf(input, "%*c %s\n", na) == 1) ){
newFile(na, matrix);
}
}
Does anyone have advice on how to check if the name is between " " and what scanning function is best?