4
I am developing a system for the college and I would like to know what is the best option, in the sense of optimization of the code, of improving even.
I have a switch
Menu case, where I have 88 cases.
I have a screen called "Help", on this screen, the user can choose between 88 screens.
Example below:
To access the "Help" screen, he must type "help"
You will access this screen telaAjuda ();
with several options within it.
Such options are between 1 and 88. Example below:
printf("\n\t Op1 ...................................1\n");
printf("\n\t Op2....................................2\n");
printf("\n\t Op3....................................3\n");
printf("\n\t Op4....................................4\n");
printf("\n\t Op5...................................5\n\n");
...
printf("\n\t Op88...................................88\n\n");
And according to what is chosen, the user is taken to another screen of determined number (as if it were a book paging scheme).
If he chooses and type the number 3, he will be taken to screen Op3.
The screen I use the switch case
is the subMenu_Ajuda ()
,who calls her under the help(I made two separate functions for this, because if I want to call the help submenu elsewhere in the code, I won’t necessarily need to call the help screen together), just to receive the value typed by the user and from it, choose the option on switch case
.
Example below subMenu_help:
printf("\nnomePrograma : loginUsuario -> "); //usarlogin
scanf("%i", &opAjuda);
switch (opAjuda) { //88 Cases
case 1:
system("clear");
telaAjuda1 ();
__fpurge(stdin);
break;
case 2:
system("clear");
telaAjuda2 ();
__fpurge(stdin);
break;
...
case 88:
system("clear");
telaAjuda88 ();
__fpurge(stdin);
break;
}
I can leave the switch case
same size or better I create a vector for all cases
and call you when necessary?
It is possible, would have to create a vector with pointers to function. It is a more advanced feature that you should not have learned yet. You want me to put an answer?
– Maniero
Yeah, we’re on file-saving now. We’re not there yet. If you can show me the way, I’d appreciate it. Just where to look and what to look for helps me a lot.
– Marcielli Oliveira
What the fpurge does?
– Leonardo
__fpurge(stdin); is used on linux, is the same thing as fflush(stdin); windows ;)
– Marcielli Oliveira