0
I’m developing a simple app for college work, and I have doubts about using the function main()
in the code for instead of going out back to the beginning of the program, this would be good practice or not?
Below I have an example in my role cadastro()
, note that at the end of the program I put the main()
, if the user type 4, 5 or any other key, so that it does not exit the program.
void cadastro(){
int op;
static int linha;
cabecalhoCadastrar();
do{
//printf(":::::Cadastrar cliente:::::\n\n");
if(linha >= 5){
printf("\nAgenda lotada!\n");
break;
}
else{
printf("\nNome: ");
fflush(stdin);
fgets(cliente[linha].nome, 50, stdin);
printf("Telefone: ");
fflush(stdin);
scanf("%d", &cliente[linha].telefone);
/* printf("Endereço: (rua, número, complemento): ");
fflush(stdin);
fgets(cliente[linha].endereco, 150, stdin);*/
linha++;
printf("\nCliente cadastrado com sucesso!\n\n\n");
system("pause");
system("cls");
cabecalhoCadastrar();
printf("\n1- Cadastrar cliente\n2- Sair\n");
fflush(stdin);
scanf("%d", &op);
system("cls");
}
}while(op == 1);
main();
}
Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).
– Maniero