fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct{
  5. int code; //код товару
  6. char name[15]; //назва товару
  7. int UAH; //Цiна товару
  8. int k; //кiлькiсть товару
  9. } Storage;
  10.  
  11. int compare(const void * a_, const void * b_)
  12. {
  13. Storage * a = (Storage *)a_;
  14. Storage * b = (Storage *)b_;
  15. return strcmp(a->name,b->name);
  16. }
  17.  
  18. int main()
  19. {
  20. Storage storage[6] = {
  21. {6745, "Headphone", 400, 30},
  22. {9399, "Tablet", 16300, 44},
  23. {9476, "Laptop", 18600, 20},
  24. {4584, "Computer mouse", 600, 39},
  25. {9455, "Phone case", 200, 16},
  26. {2683, "Phone", 18800, 17}
  27. };
  28.  
  29. qsort(storage,6,sizeof(Storage),compare);
  30.  
  31. printf("Code Product name Price Amouny\n");
  32.  
  33.  
  34.  
  35. for(int i = 0; i < 6; i++)
  36. {
  37. printf("%4d\t %15s\t %5d\t %2d\n", storage[i].code, storage[i].name, storage[i].UAH, storage[i].k);
  38. }
  39. printf("\n");
  40. }
  41.  
  42.  
Success #stdin #stdout 0s 5352KB
stdin
Standard input is empty
stdout
Code        Product name         Price  Amouny
4584	  Computer mouse	   600	 39
6745	       Headphone	   400	 30
9476	          Laptop	 18600	 20
2683	           Phone	 18800	 17
9455	      Phone case	   200	 16
9399	          Tablet	 16300	 44