input file 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:

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;
}
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Please stop creating the same thread. I see it 4 times now.
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
The program only reads two integers, so just use Notepad to create input.txt containing something like:
Code:
27 36