// Private to the do_social function for qsort. static int sort_socials(const void *v1, const void *v2) { int i1 = *(int *) v1, i2 = *(int *) v2; return strcmp(social_table[i1].name, social_table[i2].name); } // Replacement for the do_socials function. void do_socials (CHAR_DATA * ch, char *argument) { char *buf; int count = 0, match = 0, col = 0, social[maxSocial]; // Prepare for the quicksort. for (count = 0; social_table[count].name[0] != '\0'; ++count) social[count] = count; // Here use a quick-sort to get them in order. Yay. qsort(social, count, sizeof(int), sort_socials); // Loop through all entrii of our newly aquisitioned social array. for (match = 0; match < count; ++match) { //Perfect fit. count = strlen(social_table[social[match]].name) + 1; if (count < 13) count = 13; // Needs to be at least this size.. :) buf = malloc(count * sizeof(char)); sprintf(buf, "%-12s", social_table[social[match]].name); send_to_char(buf, ch); if (++col % 6 == 0) send_to_char("\r\n", ch); free(buf); } if (col % 6 != 0) send_to_char ("\n\r", ch); return; }