Sorting 3 arrays alphabetically
Greetings everyone,
I am writing a program that allows the user to enter the first name, last name, and grade of each student. The program then sorts all the names alphabetically by last name, and display a list of all the students names and grades in alphabetical order.
I don't understand how can I associate to print out the first name and the points o that same array.
I managed to make the output sort them by last name and output them, too. But the names remain unswapped.
So when I input:
Angelina Zellweger 11
Suzy Applegate 55
it should give:
Suzy Applegate 55
Angelina Zellwegerr 11
but mine outputs this:
Angelina Applegate
Suzy Zellweger
Code:
for ( j = 0; j < cnum -1; j++){
posMin = j;
for (i = j+1; i < cnum; i++)
if (strcmp(last[i], last[posMin]) < 0)
posMin = i;
strcpy(tmp,last[j]);
strcpy(last[j],last[posMin]);
strcpy(last[posMin],tmp);
}
for (i = 0; i < cnum; i++)
printf("Last name is [%i] = %s\n",i,last[i]);
That's the code for sorting the last name array.
Any help would be appreciated, thanks.