ok, missing something here... with this code:-
Code:
#include <fstream>
#include <stdio.h>
int main(){
int a[9][9];
FILE* fin;
int i, j, ch;
if(!(fin=fopen("sudoku.in","r"))){
printf("Error opening file\n");
return -1;
}
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 */
for (i=0; i < 9; ++i)
{
for (j=0; j < 9; ++j)
printf("a[%d][%d]=%d ", i, j, a[i][j]);
}
}
fclose(fin);
/* do what ever with the 2d array */
return 0;
}
the out
it reads in the first row from sudoku.in correctly, from then on the numbers are like 398934939... wheres it going wrong? is it incorrect the way i have numbers in sudoku.in