#include #include "cell.h" int load(FILE *f, struct cell (*b)[9][9]) { int x = 0; int y = 0; char c = '\0'; while (y < 9) { c = fgetc(f); switch(c) { case ' ': case '\n': case '\t': case '|': /* skip whitespace, | */ continue; case '_': case '?': /* blank = same as 0 */ c = '0'; /* fallthrough */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': (*b)[x][y].val = c - '0'; break; case EOF: printf("Unexpected EOF when filling (%d,%d)\n", x, y); return -1; default: printf("Unexpected '%c' when filling (%d,%d)\n", c, x, y); return -1; } /* move to next position in board */ if (++x == 9) { x = 0; y++; } } return 0; }