Yeah I actually got that and fixed it with:
Code:
fscanf(puzzle_file, "%1d%1d%1hd", &row, &col, &val)
Regardless, I now had to check for errors in the input file and read in each field as a string anyway. Lines can have more than 3 characters in them, and I'm supposed to just ignore everything past those first ones.
Code:
void configure(FILE *puzzle_file) {
int row = 0 ;
int col = 0 ;
short val = 0 ;
char linestr[100] ;
int fline = 1 ;
while( fscanf(puzzle_file, "%s\n", linestr) != EOF ) {
row = linestr[0]-48 ; col = linestr[1]-48 ; val = linestr[2]-48 ;
if( !in_range(row) || !in_range(col) || !in_range(val) ) {
printf("Illegal format in configuration file at line %d\n", fline) ;
exit(1) ;
}
if( puzzle[row][col] != 0 ) {
printf("Illegal placement in configuration file at line %d\n", fline) ;
exit(1) ;
}
puzzle[row][col] = val ;
fixed[row][col] = TRUE ;
fline++ ;
}
return ;
}
This works perfectly well. Everything compiles and runs smoothly. Thing is, does checking against EOF work the same as using feof? I assume no, but I can't be sure.