Obj; Read numbers from input file,
Store them in a 2-dimensional array,
and then Print the data.
Data File; INPUT.TXT ======================
5 12
9 9
9 21
10 4
11 13
15 16
17 9
19 5
20 15
21 11
=> Store input data into Dat (2-dim) array;
0 0 0
0 5 12
0 9 9
0 9 21
0 10 4
0 11 13
0 15 16
0 17 9
0 19 5
0 20 15
0 21 11
; Dat[[1..N][1,2]; data region
Locations where zeroes are present may be used for some other purpose.
Program =====================================
FILE *INF; // INF; input file pointer
#define N 4 // num of data pts.
int Dat[N+1][2+1]; // data N*2 Matrix Dat[1..N][1,2]
main() {
int row, col;
// Open INPUT.TXT
if ((INF=fopen("INPUT.TXT","r"))==NULL) {
printf("\nERROR: cannot open input file - INPUT.TXT \n ");
getch(); exit(0);
}
// Read Data from INPUT.TXT
for(row=1; row<=N; row++) { // read data pts
fscanf(INF,"%d %d", &Dat[row][1],&Dat[row][2]); // (x,y) coord
}
// Print Data from Dat[][]
printf("\n\n SHOW Dat[] ------------ ");
for(row=1; row<=N; row++) { // Init.Dat[][]
printf("\n%5d: ",row);
for (col=1; col<=2; col++) { printf("%5d ",Dat[row][col]); }
}
printf("\n-------------------------- ");
fclose(INF); // close input file pointer
} // main()