Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define tam 20
  5.  
  6. typedef struct endereco{
  7.     char rua[100], numero[5], bairro[50];
  8. }Tendereco;
  9.  
  10. typedef struct fone{
  11.     char res[12], com[12], cel[12];
  12. }Tfone;
  13.  
  14. typedef struct contato{
  15.     char nome[100], emails[3][50];
  16.     Tendereco ender;
  17.     Tfone fones;
  18. }Tcontato;
  19.  
  20.  
  21. void preencher(Tcontato agenda[]);
  22. int consultar(Tcontato agenda[], char nome[]);
  23. void exibir(Tcontato agenda);
  24.  
  25.  
  26. int main() {
  27.  
  28.     Tcontato agenda[tam];
  29.     char nome[100],resp;
  30.     int pos;
  31.  
  32.  
  33.     preencher(agenda);
  34.  
  35.     do{
  36.         printf("\nInforme o nome a consultar: ");
  37.             fgets(nome,99,stdin);fflush(stdin);
  38.         pos=consultar(agenda,nome);
  39.  
  40.         if(pos!=-1)
  41.             exibir(agenda[pos]);
  42.         else
  43.             printf("\nA pessoa nao esta cadastrada!");
  44.         do{
  45.             printf("\nDeseja consultar outra nome?");
  46.                 resp=toupper(getchar());fflush(stdin);
  47.         }while(resp!='S'&&resp!='N');
  48.     }while(resp=='S');
  49.  
  50.     return 0;
  51. }
  52.  
  53.  
  54. void preencher(Tcontato agenda[]){
  55.     int i, qtd=0;
  56.     char resp;
  57.  
  58.     for(i=0;i<tam;i++){
  59.         printf("\nInforme o nome: ");
  60.             fgets(agenda[i].nome,99,stdin);fflush(stdin);
  61.         do{
  62.             strcpy(agenda[i].fones.res," ");
  63.             strcpy(agenda[i].fones.com," ");
  64.             strcpy(agenda[i].fones.cel," ");
  65.  
  66.             printf("\nInforme o email:");
  67.                 fgets(agenda[i].emails[qtd],49,stdin);fflush(stdin);
  68.             qtd++;
  69.             do{
  70.                 printf("\nDeseja cadastrar outro email?");
  71.                 scanf("%c",&resp);fflush(stdin);
  72.                 resp=toupper(resp);
  73.             }while(resp!='S'&&resp!='N');
  74.         }while(resp='S'&&qtd<3);
  75.  
  76.         printf("\nInforme a rua:");
  77.             fgets(agenda[i].ender.rua,99,stdin);fflush(stdin);
  78.         printf("\nInforme o numero:");
  79.             fgets(agenda[i].ender.numero,4,stdin);fflush(stdin);
  80.         printf("\nInforme o bairro:");
  81.             fgets(agenda[i].ender.bairro,44,stdin);fflush(stdin);
  82.  
  83.  
  84.  
  85.         printf("\nTELEFONES");
  86.  
  87.         do{
  88.             printf("\n1-Residencial 2-Comercial 3-Celular 4-Sair");
  89.                 scanf("%c",&resp);fflush(stdin);
  90.             switch(resp){
  91.                 case'1':    printf("\nInforme o fone:");
  92.                             fgets(agenda[i].fones.res,11,stdin);fflush(stdin);
  93.                             break;
  94.  
  95.                 case'2':    printf("\nInforme o fone:");
  96.                             fgets(agenda[i].fones.com,11,stdin);fflush(stdin);
  97.                             break;
  98.  
  99.                 case'3':    printf("\nInforme o fone:");
  100.                             fgets(agenda[i].fones.cel,11,stdin);fflush(stdin);
  101.                             break;
  102.  
  103.                 case'4':    break;
  104.  
  105.             }
  106.  
  107.         }while(resp!='4');
  108.     }
  109. }
  110.  
  111.  
  112. int consultar(Tcontato agenda[], char nome[]){
  113.     int i;
  114.  
  115.     for(i=0;i<tam;i++){
  116.         if(strcmp(agenda[i].nome,nome)==0)
  117.             return i;
  118.         else
  119.             return -1;
  120.     }
  121.  
  122.  
  123. }
  124.  
  125.  
  126. void exibir(Tcontato agenda){
  127.     int i;
  128.  
  129.     printf("\nNome: %s",agenda.nome);
  130.     for(i=0;i<3;i++)
  131.         printf("\nEmail: %s",agenda.emails[i]);
  132.     printf("\nEndereco: %s, %s, %s.",agenda.ender.rua, agenda.ender.numero,agenda.ender.bairro);
  133.     printf("\n-FONES-");
  134.     printf("\nResidencial: %s\nComercial: %s\nCelular: %s",agenda.fones.res,agenda.fones.com,agenda.fones.cel);
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement