Advertisement
alyne071092

Untitled

Mar 28th, 2015
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct contatos
  5. {
  6. char nome[50];
  7. int telefone;
  8. char email[20];
  9.  
  10. };
  11.  
  12. int main()
  13. {
  14. struct contatos *ptr; // declarar um ponteiro pra contatos....
  15. struct contatos *ptr_telefones;
  16. struct contatos *ptr_email;
  17. int i, n,c,l;
  18. char nomea[20];
  19. char resposta,respostaemail;
  20. int numero,numeroemail;
  21.  
  22. printf("Digite o numero de registros? ");
  23. scanf("%d",&n);
  24.  
  25. ptr = (struct contatos*)malloc(n*sizeof(struct contatos));
  26.  
  27. for(i=0; i<n; ++i)
  28. {
  29. printf("Entre com o nome : ");
  30. scanf("%s",&(ptr+i)->nome);
  31.  
  32.  
  33. printf("Tem mais de um email? \n ");
  34. scanf("%s",&respostaemail);
  35. if(respostaemail=='S' || respostaemail =='s'){
  36. printf("Quantos? \n ");
  37. scanf("%d",&numeroemail);
  38. ptr_email=(struct contatos*)malloc (numeroemail*sizeof(struct contatos));
  39. for(l=0;l<numeroemail;++l){
  40. printf("Entre com o email : ");
  41. scanf("%s",&(ptr_email+l)->email);
  42.  
  43.  
  44. }
  45. }
  46.  
  47.  
  48. printf("Tem mais de um telefone? \n ");
  49. scanf("%s",&resposta);
  50. if(resposta=='S' || resposta =='s'){
  51. printf("Quantos? \n ");
  52. scanf("%d",&numero);
  53. ptr_telefones=(struct contatos*)malloc (numero*sizeof(struct contatos));
  54. for(c=0;c<numero;++c){
  55. printf("Entre com o telefone : ");
  56. scanf("%d",&(ptr_telefones+c)->telefone);
  57.  
  58.  
  59. }
  60. }
  61.  
  62.  
  63. }
  64. printf("Lista de Contatos: \n ");
  65. for(i=0; i<n; ++i)
  66.  
  67. {
  68.  
  69.  
  70. printf("Nome: %s \n ", (ptr+i)->nome);
  71. for(l=0;l<numeroemail;++l){
  72. printf("Email: %d e %s \n ",l, (ptr_email+i)->email);
  73. }
  74. for(c=0;c<numero;++c){
  75. printf("Telefone:%d e %d \n ", c,(ptr_telefones+c)->telefone);
  76. }
  77. }
  78.  
  79. printf("Digite o nome que deseja procurar? \n ");
  80. scanf("%s",&nomea);
  81. for(i=0;i<n;++i){
  82.  
  83.  
  84. if (strcmp (ptr[i].nome,nomea) ==0 )
  85. {
  86. printf("Tem o contato\n");
  87. }else{
  88.  
  89. printf("nao tem o contato\n");
  90. }
  91.  
  92. }
  93.  
  94.  
  95.  
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement