#include <stdio.h>
#include <stdlib.h>
typedef struct {
int a;
int b;
const char *label;
} Item;
Item data[] = {
{7, 2, "python"},
{8, 3, "c"},
{3, 5, "c++"},
{4, 1, "c#"},
{3, 2, "java"},
{7, 1, "go"},
{1, 2, "rust"},
};
int cmp_items(const void *p1, const void *p2) {
const Item *x = p1;
const Item *y = p2;
if (x->a != y->a)
return x->a - y->a; // sort by first column
return x->b - y->b; // then by second column
}
int main(void) {
int count = sizeof(data) / sizeof(data[0]);
qsort(data, count, sizeof(Item), cmp_items);
for (int i = 0; i < count; i++) {
printf("(%d, %d, %s)\n", data[i].a, data[i].b, data[i].label);
}
return 0;
}
/*
run:
(1, 2, rust)
(3, 2, java)
(3, 5, c++)
(4, 1, c#)
(7, 1, go)
(7, 2, python)
(8, 3, c)
*/