Code:
#include <fstream>
#include <stdio.h>
int main()
{
/* sudoku array */
int a[9][9];
FILE* fin;
int i, j, ch;
if(!(fin=fopen("sudoku.in","r")))
{
printf("Error opening file\n");
return -1;
}
/* input loop to read in sudoku array from sudoku.in */
for(i=0; i < 9 && !feof(fin); ++i)
{
for(j=0; j < 9 && !feof(fin); ++j)
{
a[i][j] = fgetc( fin ) - '0';
if(a[i][j] == '\n'){
printf("Error reading from file\n");
return -1;
}
}
ch=fgetc(fin); /* discard '\n' on the line */
}
/* output loop to output the new 9x9 array */
for (i=0; i < 9; ++i)
{
for (j=0; j < 9; ++j)
printf("a[%d][%d]=%d ", i, j, a[i][j]);
}
fclose(fin);
}
return 0;
}
ok thanks! i finally tweaked it so the file io is right, it reads from the file into the array..
how would one go about scanning each row and each column in the array to see if numbers are repeated per row/column..?