Guest User

Untitled

a guest
Apr 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define SIZE 16
  5. #define N 5
  6.  
  7. struct Prova
  8. {
  9. char nome[SIZE];
  10.  
  11. };
  12.  
  13.  
  14.  
  15. void sort(struct Prova *ptr)
  16. {
  17. char temp[SIZE];
  18.  
  19. for(int i = 0; i < N; i++)
  20. {
  21. for(int j = i+1; j < N; j++)
  22. {
  23.  
  24. if(strcmp((ptr+i)->nome,(ptr+j)->nome) < 0)
  25. {
  26. strcpy(temp, (ptr+i)->nome);
  27. strcpy((ptr+i)->nome,(ptr+j)->nome);
  28. strcpy(temp, (ptr+j)->nome);
  29. }
  30. }
  31.  
  32. }
  33.  
  34. }
  35.  
  36.  
  37.  
  38. int main()
  39. {
  40. struct Prova * ptr;
  41.  
  42. ptr = (struct Prova*)malloc(N * sizeof(struct Prova));
  43.  
  44. for(int i = 0; i< N; i++)
  45. {
  46. scanf(" %s", (ptr+i)->nome);
  47. }
  48.  
  49. sort(ptr);
  50.  
  51. for(int i = 0; i< N; i++)
  52. {
  53. printf("%sn", (ptr+i)->nome);
  54. }
  55.  
  56. }
Add Comment
Please, Sign In to add comment