
08-12-2007, 21:57
|
|
|
|
חבר מתאריך: 13.11.07
הודעות: 8
|
|
|
שאלה ב-C. מה אני עושה לא בסדר?
ערב טוב.
כבר שלושה ימים אני יושב על הקוד הזה ולא מצליח להבין מה עשיתי לא בסדר...
אשמח אם תוכלו להביט על מה שעשיתי ולהגיד למה זה לא עובד. משהו לא בסדר כנראה בהגדרת המערך הדו מימדי בכניסה לפונקציה. ה-debugger בהרצה מודיע משהו בסגנון can not evaluate
והנה הקוד...
#include<stdio.h>
#define empty 0
#define player 1
#define computer -1
//void clean_board(int board[row][col],int row,int col);
void print_board(int board[9][9],int n,int row,int col);
//int player_move(int board[n][n],int row,int col);
void main()
{
int board[9][9]={empty};
int n=0;
do
{
printf("Welcome To X0\n");
printf("Please enter n:\n");
scanf("%d",&n);
printf("\n");
print_board(board[n][n],n,0,0);
//player_move(board[n][n],0,0);
}
while(n!=0);
//clean_board(board[9][9],0,0);
}
/*void clean_board(int board[row][col],int row,int col)
{
for(row=0;row<9;row++)
{
for(col=0;col<9;col++)
{
board[row][col]=empty;
}
}
}*/
void print_board(int board[9][9],int n,int row,int col)
{
int i,j;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(board[i][j]==empty)
{
printf("| ",board[i][j]);
}
if(board[i][j]==player)
{
printf("|X",board[i][j]);
}
if(board[i][j]==computer)
{
printf("|0",board[i][j]);
}
}
printf("|");
printf("\n");
}
printf("\n");
//return;
}
/*int player_move(int board[9][9],int n,int row,int col)
{
char player_input[20]={0};
int i=0,j=0;
printf("Please Enter Your Choice:\n");
scanf("%s\n",player_input);
while(i!='\0'&&i<20&&j<3)
{
if(j==0&&player_input[i]!=' ')
{
row=player_input[i]-1;
j++;
}
if(j==1&&player_input[i]!=' ')
{
if(player_input[i]!=',')
{
printf("Error ,try again\n");
break;
}
else
{
j++;
i++;
if(j==2&&player_input[i]!=' ')
{
col=player_input[i]-1;
}
}
}
i++;
}
board[row][col]=player;
print_board(board[9][9],n,row,col);
}*/
|