I'm developing a simple application for college work, and I'm hesitant to use the main()
function in code so instead of going back to the beginning of the program, would that be a good practice or not?
Below I have an example in my function cadastro()
, notice that at the end of the program I put main()
, in case the user type 4, 5 or any other key, so that it does not exit the program. p>
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();
}