matrix problem

I write a code for a problem. My roblem is:
Enter n x m integers from text file
Arrange above integers on the way from from outside to inside in a certain order of the matrix nx m.
Export results to a text file.
I don't know how to make "input.txt" to make the program run perfectly. If u can, please send me ur file "input.txt"
Here is my code:

#include <stdio.h>

#define MAXN 110

int a[MAXN][MAXN], m, n;

void input(){
	scanf("%d %d", &n, &m);
}

void initial(){
	int i;
	for (i = 0; i<=n+1; ++i){
		a[i][0]=-1;
		a[i][m+1]=-1;
	}
	for (i = 0; i<=m+1; ++i){
		a[0][i]=-1;
		a[n+1][i]=-1;
	}
}

void solve(){
	int dx[] = {-1, 0 , 1, 0};
	int dy[] = {0, 1, 0, -1};
	int tx = 1, ty = 1, dir = 0, i;
	a[1][1] = 1;
	for (i = 2; i<=n*m; ++i){
		while (a[tx+dx[dir]][ty+dy[dir]]){
			dir = (dir+1)%4;
		}
		tx = tx + dx[dir];
		ty = ty + dy[dir];
		a[tx][ty] = i;
	}
}

void output(){
	int i, j;
	for (i = 1; i<=n; ++i){
		for (j = 1; j<=m; ++j){
			printf("%4d ", a[i][j]);
		}
		printf("\n");
	}
}

int main(){
	freopen("D:\input.txt", "r", stdin);
	freopen("D:\output.txt", "w", stdout);
	input();
	initial();
	solve();
	
	output();
	return 0;
}
So you wrote a reader for a file layout you don't know? That makes no sense, so I'm guessing it's a lie.

Next time, try being honest. And not posting it twice.
here is a copy of my brother's work. I don't know how to make it's work right
Then ask him.
The input file is made of two numbers that are read into n and m. This is obvious from the code having a single scanf with two "%d"s.
He have a contest and is busy with it, soI have to manage myseft for a whike. Please help me, Thank u
It looks like your "matrix" is labeled as a. You have it defined as an integer, which means it's contents should also be integers. In addition, you have two additional variables (n and m) also defined as integers. Yet from your input() function, it looks like you are trying to read these variables in as doubles.

I also can not see where you assign values to your matrix-I assume (from reading your problem) you want to read in n and m, then assign them to a[i][j]. However, the only place I see where you assign them is in your initial() function, where you assign a[i][j] either a 1 or a -1.

Also, it is not clear by what you mean by
I don't know how to make "input.txt" to make the program run perfectly.
Presumably if you know the format of your text file, then you can write your own input function to be able to read it-this is a fairly trivial thing that you should have learned when you first encountered file handling.
@Glen, %d in scanf means 'decimal' rather than 'double'.
@hamsterman Ahhh you are right-Sorry about that! It's been so long since I've used scanf, I forgot %d was decimal and not double.

OP: You can ignore my first point then :)
Topic archived. No new replies allowed.