fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int compw(const void *a, const void *b){
  5. struct data *p1 = (struct data *)a;
  6. struct data *p2 = (struct data *)b;
  7. return (p1->x) - (p2->x);
  8. }
  9.  
  10. int comph(const void *a, const void *b){
  11. struct data *p1 = (struct data *)a;
  12. struct data *p2 = (struct data *)b;
  13. return (p1->y) - (p2->y);
  14. }
  15.  
  16. int main(void){
  17. struct data{
  18. int x, y;
  19. };
  20. struct data A[5] = {{3, 4}, {1, 2}, {5, 6}, {9, 10}, {7, 8}};
  21. struct data B[5] = {{10, 9}, {8, 1}, {9, 25}, {6, 81}, {7, 49}};
  22. int i;
  23. qsort(A, 5, sizeof(struct data), compw);
  24. qsort(B, 5, sizeof(struct data), comph);
  25. for(i = 0 ; i < 5; i++){
  26. printf("(%d, %d) ", A[i].x, A[i].y);
  27. }
  28. printf("\n");
  29. for(i = 0 ; i < 5; i++){
  30. printf("(%d, %d) ", B[i].x, B[i].y);
  31. }
  32. printf("\n");
  33. system("pause");
  34. return 0;
  35. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function ‘compw’:
prog.c:7:12: error: dereferencing pointer to incomplete type ‘struct data’
  return (p1->x) - (p2->x);
            ^~
prog.c: In function ‘comph’:
prog.c:13:12: error: dereferencing pointer to incomplete type ‘struct data’
  return (p1->y) - (p2->y);
            ^~
prog.c: In function ‘compw’:
prog.c:8:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
prog.c: In function ‘comph’:
prog.c:14:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
stdout
Standard output is empty