names will not switch using bubble sort

Im trying to rank a class from least to greatest by average, but Im trying to switch the names along with them, but the names do not switch. Can someone help me out? Here is part of my code:

int i=0, j=0,test=0,n=20;
float tmp;
char tmp2[20];


for (i=0; i<n-1; i++) {
for (j=0; j<n-1-i; j++){
if (average2[j+1] < average2[j]) { /*****compare the two numbers ******/
tmp = average2[j]; /*****swap average2[j] and average2[j+1]******/
tmp2[j]=names_array[j][0];

average2[j] = average2[j+1];
names_array[j][0]=names_array[j+1][0];

average2[j+1] = tmp;
names_array[j+1][0]=tmp2[j];
}
}
}
What is the declaration of names_array?

Here it looks like you're swapping just the first character. Why don't you use:
strcpy(char* temp, char* names);

You can also use the "Code" format to paste your code, its easier to go through.
names_array is a char array. Thanks i will try strcpy
Topic archived. No new replies allowed.