fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct PATIENT
  5. {
  6. char sex[15];
  7. char name[30];
  8. char surname[15];
  9. int diagnosis;
  10. int date[1];
  11. } PATIENT;
  12.  
  13. int cmp(const void * a, const void * b)
  14. {
  15. return strcmp(((const PATIENT*)a)->surname,((const PATIENT*)b)->surname);
  16. }
  17.  
  18. int main()
  19. {
  20. PATIENT massive[5] = {{"","abc","def"},{"","xzy","vcd"},{"","hfk","hdb"},{"","ghd","vqw"},{"","ffg","ijk"}};
  21.  
  22. for(int i = 0; i < 5; ++i) printf("%s\t",massive[i].surname); puts("");
  23.  
  24. qsort(massive,5,sizeof(PATIENT),cmp);
  25.  
  26. for(int i = 0; i < 5; ++i) printf("%s\t",massive[i].surname); puts("");
  27. }
  28.  
Success #stdin #stdout 0s 5512KB
stdin
Standard input is empty
stdout
def	vcd	hdb	vqw	ijk	
def	hdb	ijk	vcd	vqw