c 中的 tic tac toe - 预期的表达式 - 怎么了?
tic tac toe in c - Expected expression - what's wrong?
我正在尝试用 c 构建井字游戏。
我必须要求用户选择尺寸(3 * 3 / 4 * 4 / ..)
问题是它一直告诉我有问题..这是我的代码:
#include <stdio.h>
#include <stdlib.h>
void printBoard(char** board, int size)
{
int i,j;
printf("\n");
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
printf("[%c] ",board[i][j]);
}
printf("\n");
}
}
int main()
{
int i,j,size;
printf("Enter the dimensions of the board: ");
scanf("%d %d",&i,&j);
if (i != j)
{
printf("Input error!");
return 0;
}
if (i == j)
{
char **board;
board = malloc(i*sizeof(char*));
for(int c=0; c < i; c++)
{
board[c] = malloc(c*sizeof(char));
}
size = i = j;
printBoard(char **board,int size); /// Expected expression - what's wrong?
}
}
-- printBoard(char **board,int size); /// Expected expression - what's wrong?
++ printBoard(board,size); /// Fixed
我正在尝试用 c 构建井字游戏。 我必须要求用户选择尺寸(3 * 3 / 4 * 4 / ..) 问题是它一直告诉我有问题..这是我的代码:
#include <stdio.h>
#include <stdlib.h>
void printBoard(char** board, int size)
{
int i,j;
printf("\n");
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
printf("[%c] ",board[i][j]);
}
printf("\n");
}
}
int main()
{
int i,j,size;
printf("Enter the dimensions of the board: ");
scanf("%d %d",&i,&j);
if (i != j)
{
printf("Input error!");
return 0;
}
if (i == j)
{
char **board;
board = malloc(i*sizeof(char*));
for(int c=0; c < i; c++)
{
board[c] = malloc(c*sizeof(char));
}
size = i = j;
printBoard(char **board,int size); /// Expected expression - what's wrong?
}
}
-- printBoard(char **board,int size); /// Expected expression - what's wrong?
++ printBoard(board,size); /// Fixed