whoami-r Posted May 31, 2018 at 06:03 PM Report #610805 Posted May 31, 2018 at 06:03 PM Boas pessoal, tenho um trabalho que consiste em fazer um programa de gestão de uma loja. Neste momento ainda estou a fazer (ou a tentar) o registo de um novo cliente. Já criei uma parte do código, mas estou com problemas quando insiro o NIF. O nome fica guardado na váriavel que criei mas o NIF apresenta um número diferente daquele que é digitado, talvez um numero que esteja guardado na memória. Se me puderem ajudar a resolver este problema, agradecia. P.S. Inseri o código que já fiz mas o problema em si está na ultima função ("obtem_info()") Obrigado #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 100 typedef struct dados { char nome[50]; int nif; int n_alugueres; } cliente; void menuPrincipal(); void registarCliente(); cliente obtem_info(); int opcao; int main(int argc, char** argv) { printf("Bem Vindo ao Guitarras P'Alugar!!!\n"); menuPrincipal(); return (EXIT_SUCCESS); } void menuPrincipal() //falta implementar funçoes { cliente loja[MAX]; int total = 0; do { printf("\n\nMENU PRINCIPAL\n\n"); printf("1 - Registar Cliente\n"); printf("2 - Excluir Cliente\n"); printf("3 - Listar Clientes Ativos\n"); printf("4 - Listar Clientes Banidos\n"); printf("5 - Sair\n\n"); printf("Opcao: "); scanf("%d", &opcao); switch (opcao) { case 1: fflush(stdin); system("cls"); registarCliente(loja,&total); break; case 2: fflush(stdin); system("cls"); //excluirCliente(loja,&total); break; case 3: fflush(stdin); system("cls"); //listarAtivos(); break; case 4: fflush(stdin); system("cls"); //listarBanidos(); break; } }while(opcao != 5); printf("\nObrigado e Ate Breve!\n"); } void registarCliente(cliente tab[], int* n) { printf("Atualmente a loja possui %d clientes\n\n",*n); if (*n >= MAX) { printf("Loja cheia!"); } else { tab[*n] = obtem_info(); (*n)++; } } cliente obtem_info() { cliente t; printf("Nome: "); scanf("%s", t.nome); printf("\nNIF: "); scanf("%d",t.nif); //É AQUI QUE ESTÁ O PROBLEMA printf("Nome Introduzido: %s\n",t.nome); printf("NIF Introduzido: %d",&(t.nif)); return t; }
HappyHippyHippo Posted May 31, 2018 at 07:43 PM Report #610806 Posted May 31, 2018 at 07:43 PM a todos os scanf's, altera o formato de leitura para ter um espaço logo após a abertura das aspas. IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now