nikolas_serafini

Lista 5 - Exercício 22

Jul 7th, 2013
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #define MAXWORDS 30
  4. #define MAXNAME 50
  5.  
  6. int main()
  7. {
  8.     int position = 0,i,j,k;
  9.     char names[MAXNAME][MAXWORDS],test[MAXWORDS];
  10.  
  11.     while (1) {
  12.         printf("Entre com um nome: (tecle 'Fim' para sair)\n");
  13.         gets(test);
  14.        
  15.         if (strcmp(test,"Fim") == 0 || strcmp(test,"fim") == 0)
  16.             break;
  17.         else {
  18.             strcpy(names[position],test);
  19.             position++;
  20.         }
  21.     }
  22.  
  23.     k = position-1;
  24.     for (i = 0; i < position; i++){
  25.         for (j = 0; j < k; j++) {
  26.             if (strcmp(names[j],names[j+1]) > 0) {
  27.                 strcpy(test,names[j]);
  28.                 strcpy(names[j],names[j+1]);
  29.                 strcpy(names[j+1],test);
  30.             }
  31.         }
  32.         k--;
  33.     }
  34.  
  35.     printf("Lista ordenada alfabeticamente :\n");
  36.     for (i = 0; i < position; i++)
  37.         puts(names[i]);
  38.    
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment