Part of my homework is to manipulate a 2D array filled with team scores using functions. I'm having trouble with the function where they want me to print all scores ordered by opponents from least to greatest. Here is what I have.
#include <stdio.h>
void arrangeScores(int array[][50], int team){
int low = array[0][0], tempArray[2][50], i, j = 0, instance = 1, flag, done = 0;
while(done == 0){ //perform while list is being sorted
for(i = 1; i < 50; ++i){ //checks for low value skipping flag number
if(array[team][i] == -999)
continue;
else if(array[team][i] < low)
low = array[0][i];
else
++instance; //handles duplicates
}
while(instance != 0){ //loads temp array
tempArray[team][j] = low;
for(i = 0; i < 50; ++i){
if(array[team][i] == low){
tempArray[team + 1][j] = array[team + 1][i];
array[team][i] = -999;
}
}
++j;
--instance;
}
instance = 1;
flag = 0;
for(i = 0; i < 50; ++i){ //checks to see if list is all flags(empty)
if(array[team][i] == -999)
++flag;
else if(flag == 49)
done = 1;
}
for(i = 0; i < 50; ++i) //updates low to new number
if(array[team][i] != -999 && array[team][i] != low){
low = array[team][i];
break;
}
}
for(i = 0; i < 50; ++i){ //reinitalizes origional array from sorted numbers
array[team][i] = tempArray[team][i];
array[team + 1][i] = tempArray[team + 1][i];
}
}
int main(){
int array[2][50];
int j = 0;
for(int i = 50; i > 0; --i){
array[0][j] = i;
++j;
}
for(int i = 0; i < 50; ++i){
array[1][i] = i;
}
arrangeScores(array, 0);
for(int i = 0; i < 50; ++i)
printf("%d %d\n", array[0][i], array[1][i]);
return 0;
}
For some reason every element in the 2nd row are all 50.