What results were you expecting? It looks like you have some parenthesis out of place. Here is the pseudocode of what I think you were trying to do (indentation is used instead of parenthesis).
Code:
#include <stdio.h>
int main void
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
printf "read from file: \n%d %d\n", rowsize,colsize
for i = 0; i < rowsize; ++i
for j = 0; j < colsize; ++j
fscanf cap, "%d", &mat[i][j]
printf "%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
printf "\n"
printf "\nresult:\n"
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
return 0
Anchor, a free, GPL project I'm working on: Anchor | freshmeat.net will convert the above pseudocode to C and compile it producing this result:
Code:
read from file:
3 4
1 4 5 4
4 5 6 5
1 2 2 3
result:
3 2 5 1
4 5 6 5
1 4 2 1
This is what Anchor sends to the compiler. Just be sure to tell it if you prefer -tabs.
Code:
#include <stdio.h>
int main (void){
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);
printf ("read from file: \n%d %d\n", rowsize,colsize);
for (i = 0; i < rowsize; ++i){
for (j = 0; j < colsize; ++j){
fscanf (cap, "%d", &mat[i][j]);
printf ("%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;
} printf ("\n");
} printf ("\nresult:\n");
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);
return 0;
}
Be sure to vote for my project if you find it useful.