I was studying for a quiz and while writing the code I faced a problem.
My code skips the gets()
function. If I use scanf
it wont skip but since I'm scanning a full name using scanf
would be troublesome but gets()
is skipped for some reason.
struct Conta{
char nomeDoCliente[50];
int numeroDeConta;
float saldoDeConta;
};
struct Conta conta1;
int main()
{
switch (menu()){
case 1 :
defDadosDeConta();
break;
case 2 :
break;
case 3 :
break;
}
}
int menu(){
int escolha;
puts("1 - Definir dados da conta.");
puts("2 - Depositar Dinheiro.");
puts("3 - Levantar Dinheiro.");
puts("4 - Sair.");
printf("Escolha a sua operação: ");
scanf("%d", &escolha);
return escolha;
}
defDadosDeConta(){
printf("Insira o seu nome: ");
gets(conta1.nomeDoCliente);
puts("Dados de conta guardados com sucesso!");
}