qsort( ) on a structured array
I've searched online on the qsort( ) function and on this forum but cannot seem to find a lot of information on how to sort an array of structs. I seemed to get this code to compile but when I go to print out the array, it seems that the entire array is null. I've initialized the array already but didn't think anyone would need that. Here's only the code I'm having a problem with:
PHP Code:
/* an entry in Operation Table */
struct ot_entry {
char ot_mnemonic[OP_LENGTH + 1];
int ot_format;
};
/* array of entries */
struct ot_entry *optbl[OT_SIZE];
int compare_elements(const void *ptr1, const void *ptr2){
return strcmp(((struct ot_entry*)ptr1)->ot_mnemonic, ((struct ot_entry*)ptr2)->ot_mnemonic);
}
// sort Operation Table
void sortOpTbl(optbl){
qsort(optbl, sizeof(struct ot_entry), ot_count, compare_elements);
}
int main(){
sortOpTbl(optbl);
return 0;
}
Thanks in advance if anyone can help me figure out what I'm doing wrong.. :)