enum rarity
{
common,
uncommon,
rare,
mythic
};
struct card
{
unsigned int id;
char* name;
char* cost;
unsigned int converted_cost;
char* type;
char* text;
char* stats;
enum rarity rarity;
} card_t ;
I have 4 entries in my card struct. For example, card[0]->name = "Stolen by the Fae", card[1]->name = "Eternal Isolation", card[2]->name = "Corpse Knight", card[3]->name = "Orzhov Enforcer".
qsort(cards, cardsaccum , sizeof(char), cmpname);
In my qsort(), I think I'm putting in the correct parameters. My cardsaccum = 4, sizeof(char) is set because I'm checking the size of the name, then calling cmpname which sorts the names in order.
int cmpname (const void *pa, const void *pb) {
const card_t *p1 = pa;
const card_t *p2 = pb;
return strcmp(p1->name, p2->name);}
After the qsort(), my sorted entries are only the last entry read which is Orzhov Enforcer.
I don't understand why this is happening and was wondering if anyone could help explain why this is happening. Below is some of my code to better follow what I'm doing.
sizeof(char)toqsort. What is your logic there?