Advertisement
Jvsierra

Ord String Desc

May 15th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <ctype.h>
  3. #include <string.h>
  4. #include <conio.h>
  5.  
  6. #define TF 3
  7. #define LIM 51
  8.  
  9. int main()
  10. {
  11. char nomes[TF][LIM], i, aux[LIM], pos, j, k, achou;
  12.  
  13. for(i = 0; i < TF; i++)
  14. {
  15. fflush(stdin);
  16. fgets(aux, LIM, stdin);
  17.  
  18. pos = 0;
  19.  
  20. for(k = 0; k < i; k++)
  21. {
  22. achou = 0;
  23.  
  24. for(j = 0; nomes[k][j] != '\0' && achou == 0; j++)
  25. if(nomes[k][j] != aux[j])
  26. if(toupper(aux[j]) > toupper(nomes[k][j]))
  27. {
  28. pos++;
  29. achou = 1;
  30. }
  31. else if(aux[j] < nomes[k][j])
  32. achou = 1;
  33. }
  34.  
  35. for(j = i; j > pos; j--)
  36. strcpy(nomes[j], nomes[j - 1]);
  37.  
  38. strcpy(nomes[pos], aux);
  39. }
  40.  
  41. for(i = 0; i < TF; i++)
  42. printf("%s", nomes[i]);
  43.  
  44. getch();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement