YAY! 11 errors left thanks to you guys.
Code:
#include <stdlib.h>
#include <stdio.h>
#define true 1
#define false 0
int iRow, iCol, iIndex;
/* Function declarations */
void InitializeBoard(char[3][3]);
void PrintBoard(char[3][3]);
void LocateSpace(int *, int *, char [3][3]);
void Randomize(char[3][3]);
void Move(char[3][3], const EMove);
enum EMove { Up = 'w',
Down = 'z',
Left = 'a',
Right = 's'};
int main() {
char caaBoard[3][3];
InitializeBoard(caaBoard);
Randomize(caaBoard);
do {
char cNextMove;
typedef enum EMove EMove;
enum EMove eNextMove = (EMove)cNextMove;
Move(caaBoard, eNextMove);
PrintBoard(caaBoard);
printf("\nMove? ");
scanf("%c", &cNextMove);
printf("\n");
} while (true);
return EXIT_SUCCESS;
}
void InitializeBoard(char caaBoard[3][3]) {
const char kcaaInitial[3][3] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '_'}
};
for (iRow = 0; iRow < 3; ++iRow) {
for (iCol = 0; iCol < 3; ++iCol) {
caaBoard[iRow][iCol] = kcaaInitial[iRow][iCol];
}
}
}
void PrintBoard(char caaBoard[3][3]) {
for (iRow = 0; iRow < 3; ++iRow) {
for (iCol = 0; iCol < 3; ++iCol) {
printf("%d", caaBoard[iRow][iCol];
}
printf("\n");
}
}
void LocateSpace(int &irRow, int &irCol, char caaBoard[3][3]) {
for (iRow = 0; iRow < 3; ++iRow) {
for (iCol = 0; iCol < 3; ++iCol) {
if (caaBoard[iRow][iCol] == ' ') {
irRow = iRow;
irCol = iCol;
}
}
}
}
void Randomize(char caaBoard[3][3]) {
srand(1000);
for (iIndex = 0; iIndex < 1000000; ++iIndex) {
const int kiNextMove = (rand() % 3);
switch (kiNextMove) {
case 0:
{
Move(caaBoard, Up);
break;
}
case 1:
{
Move(caaBoard, Down);
break;
}
case 2:
{
Move(caaBoard, Left);
break;
}
case 3:
{
Move(caaBoard, Right);
break;
}
}
}
}
void Move(char caaBoard[3][3], const EMove keMove) {
int iRowSpace;
int iColSpace;
LocateSpace(iRowSpace, iColSpace, caaBoard);
int iRowMove(iRowSpace);
int iColMove(iColSpace);
switch (keMove) {
case Up:
{
iRowMove = iRowSpace + 1;
break;
}
case Down:
{
iRowMove = iRowSpace - 1;
break;
}
case Left:
{
iColMove = iColSpace + 1;
break;
}
case Right:
{
iColMove = iColSpace - 1;
break;
}
}
/* Make sure that the square to be moved is in bounds */
if (iRowMove >= 0 && iRowMove < 3 && iColMove >= 0 && iColMove < 3) {
caaBoard[iRowSpace][iColSpace] = caaBoard[iRowMove][iColMove];
caaBoard[iRowMove][iColMove] = ' ';
}
}
errors:
error C2143: syntax error : missing ')' before ';' 66
error C2143: syntax error : missing ')' before '&' 72
error C2143: syntax error : missing '{' before '&' 72
error C2059: syntax error : '&' 72
error C2059: syntax error : ')' 72
error C2061: syntax error : identifier 'keMove' 112
error C2059: syntax error : '}' 145
error C2059: syntax error : ';' 112
error C2059: syntax error : ')' 112
error C2449: found '{' at file scope (missing function header?) 112
error C2146: syntax error : missing ')' before identifier 'keMove' 112
I'm stumped. Thanks!