#include <stdio.h>
#include <string.h>
void sort_names();
struct ListNames {
char names[20];
int age;
}n[6] = {
{"Ryan, Elizabeth",62},
{"McIntyre, Osborne",84},
{"DuMond, Kristin",18},
{"Larson, Lois",42},
{"Thorpe, Trinity",15},
{"Ruiz, Pedro",35},
};
int main (void) {
int i;
printf("Original List");
printf("\n-----------------------------");
for (i = 0; i < 6; i++) {
printf("\n%-20s",n[i].names);
printf(" %2i",n[i].age);
}
}
I am trying to sort the strings in the struct in alphabetical order, along with the int with the string. I am able to print it fine, but I am clueless on what to do next on calling the struct to sort it in alphabetical order. I know i am going to need an index value but I dont know how i would do that within a struct.
sort_names();;-)