Advertisement
Guest User

Ex Lista3

a guest
Dec 19th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.90 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. struct cliente{
  6.     char nome[50];
  7.     char end[100];
  8.     int tel;
  9. };
  10.  
  11. int imprime();
  12. void cadastrar();
  13. void buscar();
  14. void buscarCliente();
  15. struct cliente cadcliente();
  16.  
  17.  
  18. struct cliente vetcliente[50];
  19. int tamVetCliente = 0;
  20.  
  21. int main()
  22. {
  23.     int opcao ;
  24.    
  25.     opcao = 4;
  26.  
  27.     while (opcao != 1 && opcao != 2 && opcao != 3)
  28.         {
  29.             opcao = imprime(opcao);
  30.             if (opcao = 1)
  31.                   cadastrar();
  32.             else if (opcao = 2)
  33.                   buscar();
  34.                 else if (opcao = 3)
  35.                     {
  36.                         printf("O programa sera encerrado.");
  37.                         break;
  38.                     }
  39.             printf("Opcao nao valida.");
  40.         }
  41. }
  42.  
  43. int imprime()
  44. {
  45.     int x;
  46.    
  47.     printf("Digite a opcao desejada:\n");
  48.     printf("1 - Cadastrar o cliente.\n");
  49.     printf("2 - Buscar cliente.\n");
  50.     printf("3 - Fechar programa.\n");
  51.     scanf("%d", &x);
  52.     return x;
  53. }
  54.  
  55.  
  56. struct cliente cadcliente()
  57. {
  58.     struct cliente p1;
  59.     printf("Digite o nome: ");
  60.     gets(p1.nome);
  61.     printf("Digite o endereco: ");
  62.     scanf("%s", p1.end);
  63.     printf("Digite o telefone: ");
  64.     scanf("%d", &p1.tel);
  65.     return p1;
  66. }
  67.  
  68. void cadastrar()
  69. {
  70.     int cont;
  71.    
  72.     cont = 1;
  73.     while (cont = 1)
  74.     {
  75.         vetcliente[tamVetCliente] = cadcliente();
  76.         printf("Cliente %d cadastrado.", &tamVetCliente);
  77.         tamVetCliente++;
  78.        
  79.         printf("Deseja cadastras mais clientes?\n");
  80.         printf("1 - Sim.\n");
  81.         printf("2 - Nao.\n");
  82.         scanf("%d", &cont);
  83.     }
  84. }
  85.  
  86. void buscar()
  87. {
  88.     int num;
  89.     struct cliente clienteX;
  90.    
  91.     printf("Digite o numero do cliente (P/ sair > 51): ");
  92.     scanf("%d", &num);
  93.    
  94.     while (num < 51)
  95.     {
  96.         if (num >= tamVetCliente)
  97.             printf("Numero indexado a cliente inexistente.");
  98.         else
  99.         {
  100.             clienteX = vetcliente[num];
  101.             escrevaCliente(clienteX, num);
  102.         }
  103.     }
  104. }
  105.  
  106. void escrevaCliente(struct cliente x, int num)
  107. {
  108.     printf("Cliente %d", &num);
  109.     printf("Nome: %s\n", x.nome);
  110.     printf("Endereco: %s\n", x.end);
  111.     printf("Telefone: %d\n", x.tel);
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement