can't find error(s) in my program..help?
I have to write a program to read this matrix
3 4
1 4 5 4
4 5 6 5
1 2 2 3
I wrote it, and my program is not properly reading it.
Code:
#include <stdio.h>
int
main ()
{
FILE *cap;
int rowsize, colsize, i, j, x, y, b, c;
int mat[100][100];
cap = fopen ("mat1.txt", "r");
fscanf (cap, "%d", &rowsize);
fscanf (cap, "%d", &colsize);
for (i = 0; i < rowsize; ++i)
{
for (j = 0; j < colsize; ++j)
{
fscanf (cap, "%d", &mat[i][j]);
}
}
y = mat[0][0];
x = mat[rowsize-1][colsize-1];
mat[0][0]= x;
mat[rowsize-1][colsize-1] = y;
b = mat[0][colsize-1];
c = mat[rowsize-1][0];
mat[0][colsize-1] = c;
mat[rowsize-1][colsize-1] = b;
for (j = 1; j < colsize - 2; ++j)
{
mat [rowsize-1][j] = mat[rowsize-1][j] * 2;
}
for (i = 0; i < rowsize; ++i)
{
if (mat[i][1] % 2 == 0)
{
mat[i][1] = mat[i][1] / 2;
}
}
for (i = 0; i < rowsize; ++i);
{
for (j = 0; j < colsize; ++j)
{
printf ("%3d", mat[i][j]);
printf ("\n");
}
}
fclose (cap);
}