input file:
1 0 0
2 1 0
0 2 1
I would like to produce this in a 3x3 array on screen. My code:
#include <fstream.h>
#include <stdlib.h>
int i, j;
int matrix[3][3];
int main () {
ifstream inFile;
inFile.open("input.txt");
if (!inFile)
{
printf ("Unable to open input file");
exit(1);
}
for (i=0; i < 3; i++){
for (j = 0; j < 3; j++)
{
inFile >> matrix[i][j];
}
printf("%d\t", matrix[i][j]);
inFile.close ();
}
Could someone correct what I am doing wrong please?
Thank you :)
p.s. sorry for the ancient headers