示例#1
0
static int peekCharFromFile()
{
    // Read a character, possibly performing universal newline translation,
    // and put it in 'buf' so that the next call to getCharFromFile() finds it
    // already available.
    buf = getCharFromFile();
    return buf;
}
示例#2
0
bool gameBoardInitializeFromFile(GameBoard board, char* filename)
{
    FILE* pFile = fopen(filename, "r");
    if (NULL == pFile)
    {
        printf("Error opening the file."); //%s in mode %s.", filename, mode);
        return false;
    }

    char c = getCharFromFile(pFile);
    int i = 0;
    while (EOF != c && BOARD_SIZE != i)
    {
        int val = c-'1';
        if (indexIsValid(val))
        {
            board[i].value = val;
            board[i].permanent = true;
        }
        else if ('_' == c)
        {
            board[i].value = UNDERLINE_ELEMENT;
            board[i].permanent = false;
        }
        ++i;
        c = getCharFromFile(pFile);
    }

    fclose(pFile);

    if (BOARD_SIZE > i)
    {
        printf("Incomplete board in file.\n");
        return false;
    }
    return true;
}