Advertisement
harrisonmk

Lista em C primitiva

Jun 28th, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. struct Contato
  5. {
  6.     char nome [80];
  7.     char fone [14];
  8. } agenda[50];
  9.  
  10. int qtd = 0;
  11.  
  12.  
  13. void menu ();
  14. void adicionarContatos();
  15. void exibeContatos();
  16.  
  17. int main(int argc, char** argv)
  18. {
  19.     int i = 1;
  20.  
  21.     int opcao;
  22.     while(i == 1)
  23.     {
  24.  
  25.  
  26.  
  27.         system("cls");
  28.         menu();
  29.         scanf(" %d", &opcao);
  30.         fflush(stdin);
  31.         switch(opcao)
  32.         {
  33.         case 1:
  34.             adicionarContatos();
  35.             break;
  36.         case 2:
  37.             //  removeContatos();
  38.             break;
  39.         case 3:
  40.             exibeContatos();
  41.             break;
  42.         case 0:
  43.             exit(0);
  44.             break;
  45.  
  46.         }
  47.     }
  48.  
  49.  
  50.  
  51.     return 0;
  52. }
  53. void menu ()
  54. {
  55.     printf("1. ADICIONAR CONTATO\n");
  56.     printf("2. REMOVER CONTATO\n");
  57.     printf("3. EXIBIR CONTATO\n");
  58.     printf("0. SAIR\n");
  59.     printf("-->");
  60.  
  61. }
  62.  
  63. void adicionarContatos()
  64. {
  65.     printf ("Nome: ");
  66.     fgets(agenda[qtd].nome, 81, stdin);
  67.     printf("Fone: ");
  68.     fgets(agenda[qtd].fone, 15, stdin);
  69.     qtd++;
  70.  
  71. }
  72.  
  73. void remove ()
  74. {
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. }
  82.  
  83. void exibeContatos()
  84. {
  85.     int i;
  86.     for( i = 0; i < qtd; i++)
  87.     {
  88.         printf("Nome: %s", agenda[i].nome);
  89.         printf("Fone: %s\n", agenda[i].fone);
  90.         printf("\n");
  91.  
  92.     }
  93.     system("pause");
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement