Solution for Exercise 12-22

ex1222

#include <stdio.h>

int main()
{
    char tictactoe[3][3] = {
        '.', '.', '.',
        '.', 'X', '.',
        '.', '.', '.'
    };
    int x,y;

    /* display game board */
    puts("Ready to play Tic-Tac-Toe?");
    for(x=0;x<3;x++)
    {
        for(y=0;y<3;y++)
            printf("%c ",tictactoe[x][y]);
        putchar('\n');
    }
    return(0);
}

Output

Ready to play Tic-Tac-Toe?
. . .
. X .
. . .

Notes

* This code illustrates one of those times where it's easier to declare an initialized array than to construct code that fills the array. For a larger array, such as a chessboard, I would still initialized it using code, albeit in a function.

* Feel free to ignore a "missing braces" warning, if you happen to see one.