1
I’m a beginner in programming for a little while and I have a college task in which I must create a registration system that receives the entries the customer data and then another option that prints on the screen( case 2) this information.
But I’m having trouble printing these strings, where I believe I appear their memory locations and several random characters.
I wonder what I can do to make Strings are read correctly and if the return main()
or if the &
before the variable, there is something about this problem. Sorry for the messy and somewhat strange code
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;
}
}
Put also the structure
cliente
to know how the strings were defined. But a string defined aschar[]
orchar*
does not take the&
in thescanf
, for it is already a pointer. But if it ischar*
needs to be allocated before being used– Isac