# Sorting 3 arrays alphabetically

Discussion in 'C' started by Nephilim, Mar 20, 2011.

1. ### NephilimNew Member

Joined:
Mar 20, 2011
Messages:
1
0
Trophy Points:
0
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
X Y 5

it should give:
Suzy Applegate 55
X Y 5
Angelina Zellwegerr 11

So far I managed to sort by last name and print them out. I just don't know how to associate the points and print them accordingly;
Code:
```    int j;
char tmp[20], tmp2[20];
int posMin, tmp3;
for (j=0; j<cnum-1; j++){
posMin = j;

for (i = j+1; i < cnum; i++)
if (strcmp(cognome[i], cognome[posMin]) < 0)
posMin = i;

strcpy(tmp,cognome[j]);
strcpy(cognome[j],cognome[posMin]);
strcpy(cognome[posMin],tmp);

strcpy(tmp2,nome[j]);
strcpy(nome[j],nome[posMin]);
strcpy(nome[posMin],tmp2);
[b]
for (i = j+1; i<cnum; i++)
{
if(punteggio[i]>punteggio[posMin])
{
tmp3=punteggio[j];
punteggio[j]=punteggio[posMin];
punteggio[posMin]=tmp3;
}
}[/b]
}
```
The part in bold is wrong.
I am new to C so any help would be appreciated. Thank you