Can anyone detect anything out of place?
Well, since you didn't actually show us an example of the input...
Code:
if(!input)
{
printf("failed to open file");
}
What's the point of even checking to see if the file opened correctly if all you do is continue on regardless?
Now let's see what happens when we learn how to indent properly, shall we?
Code:
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(even if we have no file to read from...)*/
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;
}
}
Much better.
Quzah.