Advertisement
Guest User

Untitled

a guest
May 26th, 2018
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. int main() {
  4.     int opcao;
  5.     int i = 0;
  6.     int j = 0;
  7.     int n = 0;
  8.     char nome[100];
  9.     struct agenda {
  10.         char nome[100];
  11.         char telefone[20];
  12.         char email[50];
  13.         char sexo;
  14.         int idade;
  15.         float peso;
  16.         float altura;
  17.     } contatos[1000];
  18.  
  19. do {
  20.             printf(
  21.         "****MENU AGENDA ELETRONICA****\n1: Adicionar contato\n2: Excluir "
  22.         "contato\n3: Pesquisar contato\n4: Visualizar todos os contatos\n0: "
  23.         "Sair!\n");
  24.  
  25.     scanf("%d", &opcao);
  26.     switch(opcao) {
  27.     case 0:
  28.         return 0;
  29.         break;
  30.     case 1:
  31.         printf("****ADICIONAR CONTATO****\n");
  32.         printf("Digite o nome:\n");
  33.         // contatos[i].nome[100]
  34.         setbuf(stdin, NULL);
  35.         fgets(contatos[i].nome, 100, stdin);
  36.         // contatos[i].telefone[20]
  37.         printf("Digite o telefone (formato: (XX) XXXX-XXXX):\n");
  38.         setbuf(stdin, NULL);
  39.         fgets(contatos[i].telefone, 20, stdin);
  40.         // contatos[i].email[50]
  41.         printf("Digite o e-mail:\n");
  42.         setbuf(stdin, NULL);
  43.         fgets(contatos[i].email, 50, stdin);
  44.         printf("Digite o sexo:\n");
  45.         // contatos[i].sexo
  46.         setbuf(stdin, NULL);
  47.         scanf("%c", &contatos[i].sexo);
  48.         // contatos[i].idade
  49.         printf("Digite a idade:\n");
  50.         setbuf(stdin, NULL);
  51.         scanf("%d", &contatos[i].idade);
  52.         setbuf(stdin, NULL);
  53.         // contatos[i].peso
  54.         printf("Digite o peso:\n");
  55.          setbuf(stdin, NULL);
  56.         scanf("%f", &contatos[i].peso);
  57.          setbuf(stdin, NULL);
  58.         // contatos[i].altura
  59.         printf("Digite a altura:\n");
  60.          setbuf(stdin, NULL);
  61.         scanf("%f", &contatos[i].altura);
  62.  
  63.         i++;
  64.         break;
  65.     case 2:
  66.         //EXCLUINDO CONTATO !
  67.     setbuf(stdin, NULL);
  68.     fgets(nome,20,stdin);
  69.     for(n=0;n<i;n++)
  70.     {
  71.  //strcpy (string_destino,string_origem);
  72.         if(contatos[n].nome == nome)
  73.         {
  74.             for(j=n; j<i-1; j++)
  75.             //contatos[j].nome = contatos[j+1].nome;
  76.              strcpy(contatos[j+1].nome,contatos[j].nome);
  77.               strcpy(contatos[j+1].telefone,contatos[j].telefone);
  78.                strcpy(contatos[j+1].email,contatos[j].email);
  79.                contatos[j].sexo = contatos[j+1].sexo;
  80.                contatos[j].idade = contatos[j+1].idade;
  81.                contatos[j].peso = contatos[j+1].peso;
  82.                contatos[j].altura = contatos[j+1].altura;
  83.                 i--;
  84.         }
  85.     }
  86.          break;
  87.  
  88.     case 3:
  89.  
  90.  
  91.  
  92.     case 4:
  93.         printf("****VISUALIZAR TODOS OS CONTATOS****\n");
  94.         for(n=0;n < i;n++) {
  95.             printf("%s", contatos[n].nome);
  96.             printf("%s", contatos[n].telefone);
  97.             printf("%s", contatos[n].email);
  98.             printf("%c", contatos[n].sexo);
  99.             printf("\n");
  100.             printf("%d", contatos[n].idade);
  101.             printf("\n");
  102.             printf("%.2f", contatos[n].peso);
  103.             printf("\n");
  104.             printf("%.2f", contatos[n].altura);
  105.             printf("\n");
  106.         }
  107.         }
  108. } while(opcao!=0);
  109.     return 0;
  110. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement