Advertisement
Jonas_3k

//- Exercício -// - listas

Apr 27th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.20 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdlib.h>
  4. #define TAM 255
  5. typedef struct n
  6. {
  7.     char nome[TAM];
  8. }cliente;
  9. cliente nomes[100];
  10. int controlador = 0;
  11.  
  12. void ordena(void);
  13. void insere(void);
  14. void visualiza(void);
  15. void remover(void);
  16. void limpa_tela(void);
  17.  
  18.  
  19. int main()
  20. {
  21.     while(1)
  22.     {
  23.         //limpa_tela();
  24.         char opcao;
  25.         printf("Oque deseja fazer? [I]nserir,[V]isualizar,[R]emover ou [O]rdenar um nome: ");
  26.         scanf("%c",&opcao);
  27.         switch(opcao)
  28.         {
  29.             case 'i': case 'I': insere(); break;
  30.             case 'v': case 'V': visualiza(); break;
  31.             case 'r': case 'R': remover(); break;
  32.             case 'o': case 'O': ordena(); break;
  33.             //default : limpa_tela(); break;
  34.         }
  35.     }
  36. }
  37.  
  38. void ordena()
  39. {
  40.     int loop_1,loop_2;
  41.     cliente aux;
  42.     for (loop_1 = 0; loop_1 < controlador; loop_1++)
  43.     {
  44.         aux = nomes[loop_1];
  45.         loop_2 = loop_1 - 1;
  46.         while(loop_2>=0 && strcmp(nomes[loop_2].nome,aux.nome)>0)
  47.         {
  48.             nomes[loop_2+1] = nomes[loop_2];
  49.             nomes[loop_2] = aux;
  50.             loop_2--;
  51.         }
  52.     }
  53. }
  54.  
  55. void insere()
  56. {
  57.     char option;
  58.     int aux;
  59.     printf("Insita um nome para a posicao %d: ",controlador);
  60.     scanf("%s",&nomes[controlador].nome);
  61.     aux = strlen(nomes[controlador].nome);
  62.     nomes[controlador].nome[aux] = '\0';
  63.     controlador++;
  64.     fflush(stdin);
  65.     printf("\nDeseja continuar? [y/n]");
  66.     scanf("%c",&option);
  67.     if(option=='y'||option=='Y') insere();
  68. }
  69.  
  70. void visualiza()
  71. {
  72.     int conta;
  73.     for(conta = 0; conta < controlador+1; conta++)
  74.     {
  75.         printf("\n%s",nomes[conta].nome);
  76.     }
  77.     fflush(stdin);
  78.     scanf("c\n");
  79.     return;
  80. }
  81.  
  82. void limpa_tela()
  83. {
  84.     #ifdef WIN32
  85.         system("cls");
  86.     #else
  87.         system("clear");
  88.     #endif
  89.         fflush(stdin);
  90. }
  91.  
  92. void remover()
  93. {
  94.     cliente aux;
  95.     int conta = 0;
  96.     printf("Digite o nome a ser removido: ");
  97.     scanf("%s",&aux.nome);
  98.     while(conta<controlador+1)
  99.     {
  100.         if(strcmp(nomes[conta].nome,aux.nome)==0)
  101.         {
  102.             strcpy(nomes[conta].nome,"Removido..");
  103.         }
  104.         conta++;
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement