This works fine, obviously it's not your whole program. Should give you some guidance on
some particulars and confidence that the algorithm we were talking about, works OK.
Code:
/* RowSum.c Sort the matrix by the sum of their rows: for Transgalactic
*/
#include <stdio.h>
#define rowmax 4
#define colmax 4
int matrix[rowmax][colmax] = {
{ 8,4,9,7 },
{ 2,3,2,6 },
{ 5,2,2,9 },
{ 0,1,2,4 } };
int main(void) {
int i,j,k,temp, r, c, rows;
int sum[4] = { 28, 13, 18, 7 };
for(i = 0; i < rowmax - 1; i++) {
for(j = i + 1; j < rowmax; j++) {
if(sum[i] > sum[j]) {
temp = sum[i];
sum[i] = sum[j];
sum[j] = temp;
//now swap the rows elements, from row j to row i
for(k = 0; k <rowmax; k++) {
temp = matrix[i][k];
matrix[i][k] = matrix[j][k];
matrix[j][k] = temp;
}
}
}
}
//now print it
for(r = 0; r < rowmax; r++) {
putchar('\n');
for(c = 0; c < colmax; c++)
printf(" %d", matrix[r][c]);
}
getchar();
return 0;
}
Edit: I've got your whole program now, and I'm testing it.