I'm a newcomer to programming recently and I have a college assignment where I have to create a registration system that receives input from customer data and then another option that prints the information on the screen. / p>
But I'm having trouble printing these strings , where I believe their memory locations appear and several random characters.
I'd like to know what I can do to make Strings read correctly, and whether the return main()
or the &
before the variable has something to do with this problem. Sorry for the messy code and a little weird
int main(void) {
int opcao;
cliente cadastro[100];
int i;
char sair;
printf("\n1- Clientes");
printf("\n2- Automoveis");
printf("\n3- Tabela de precos e classificacao");
printf("\n4- Locacao");
printf("\n\n\n\tDigite a opcao desejada: ");
scanf("%d", &opcao);
switch (opcao)
{
case 1:
system("cls");
printf("\n1- Cadastro de Clientes");
printf("\n2- Detalhes do Clientes");
printf("\n3- Alterar/Excluir Clientes");
printf("\n\n\n\tDigite a opcao desejada: ");
scanf("%d", &opcao);
switch (opcao)
{
case 1:
do
{
system("cls");
printf("\nCadastro de Clientes\n");
printf("\nDigite o Codigo do Cliente: ");
scanf(" %d", &i);
cadastro[i].codigo = i;
system("cls");
printf("\n Codigo do Cliente: %d\n", cadastro[i].codigo);
printf("\n Nome: ");
scanf(" %[^\n]s", &cadastro[i].nome);
printf("\n RG: ");
scanf(" %s", &cadastro[i].rg);
printf("\n CPF: ");
scanf(" %s", &cadastro[i].cpf);
printf("\n Endereco: ");
scanf(" %[^\n]s", &cadastro[i].endereco);
printf("\n Carteira de Habilitacao: ");
scanf(" %[^\n]s", &cadastro[i].carteira_hab);
system("cls");
printf("\nCadastro Realizado com sucesso!");
printf("\n\n\t\t\tDeseja Realizar outro cadastro? S / N: ");
scanf(" %c", &sair);
} while (sair != 'n');
system("cls");
return main();
break;
case 2:
printf("\nDetalhes do Clientes");
printf("Digite o código do cliente: ");
scanf("%d", &i);
printf("\nNome: %s", &cadastro[i].nome);
default:
break;
}
default:
break;
}
}