transposing matrix from file to file
This is what I have, but when I run it the file that is printed out has a single number. Can anyone detect anything out of place?
Code:
#include <stdio.h>
#define max_row 20
#define max_col 20
int main(void)
{
int matrix[max_row][max_col];
int i, j, nr, nc;
FILE * input;
FILE * output;
input = fopen("data.in.txt", "r");
output = fopen("data.out.txt", "w");
if(!input)
{
printf("failed to open file");
}
/* read input*/
fscanf(input, "%d%d", &nr, &nc);
for(i = 0; i < nr; i++)
{
for(j = 0; j < nc; j++)
{
fscanf(input, "%d", &matrix[i][j]);
}
}
/* print transpose in file*/
for(j = 0; j < nc; j++)
{
for(i = 0; i < nr; i++)
{
fprintf(output, "%d ", matrix[i][j]);
}
return 0;
}
}
Thanks so much for looking at it.