If the file is presented as:
Code:
0123456789
1234567890
2345678901
3456789012
4567890123
5678901234
6789012345
7890123456
8901234567
9012345678
Then you should be able read it in with something like:
Code:
#include <stdio.h>
int main(){
int nSodukuArray[9][9];
FILE* fin;
int i, j, ch;
if(!(fin=fopen("soduku.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){
nSodukuArray[i][j]=fgetc(fin);
if(nSodukuArray[i][j] == '\n'){
printf("Error reading from file\n");
return -1;
}
}
ch=fgetc(fin); /* discard '\n' on the line */
}
fclose(fin);
/* do what ever with the 2d array */
return 0;
}
Only problem here might be that you get your array mirrored since your columns now appears to be located as rows...
But when doing calculations and displaying that cen be rearranged.