[ back to toc ]

Game

Date: 2002/05/03 14:51

Q:
I have this program code (C Program), im having problems running them, can
u help, n point out y there not workin. Im using telnet, dunno if this is
causin the problem, but can u compile n check if it works?? thx, its a
noughts n crooses game. I havent got access to a unix station till next
week, so, if it works can u tell me, and help wit n errors? all help is
appreciated.

/*Program Noughts & Crosses*/
/*To play: Enter row co-ordinate, then 'SPACE' then column co-ordinate
'ENTER'. ( row & column co-ordinates should be numbers 1,2,3, as row and
column 0 are not in use) i.e. 2 'space' 2 'ENTER'*/

#include <stdio.h>
#include <string.h> /*sets up 2 strings so names can be used*/
char oxo[4][4];
void display_grid();
int main(void)

{
int r1,c1,r0,c0,rx,cx,count;
int name1[20],name2[20]; u/*defines name1 & name2 are variables */

for(r1=1;r1<=3;r1++)

{

for(c1=1;c1<=3;c1++)

{

oxo[r1][c1]='.';
oxo[0][1]='1'; /**/
oxo[0][2]='2'; /*prints column numbers*/
oxo[0][3]='3'; /**/
oxo[1][0]='1'; /**/
oxo[2][0]='2'; /*prints row numbers*/
oxo[3][0]='3'; /**/

}

}

printf("\n Player 1 what is your name?\n" ); /*asks player 1 1s name*/

scanf("%s",name1); /*reads name*/

printf("\nHello %s you place the '0's & you go first! \n",name1); /*print
out */

printf("\n Player 2 what is your name?\n"); /*asks player 1 2s name*/

scanf("%s",name2); /*reads name*/

printf("\nHello %s you place the 'X's & you go second! \n",name2); /*print
out */

display_grid();

count=0;

while(count<9)

{

if(count<9)

{

do{

printf("%s enter you next move, '0's",name1); /*asks for m move by name*/

scanf("%d%d",&r0,&c0);

}

while((oxo[r0][c0]!='.')||(oxo[r0][c0]=='X')||(oxo[r0][c0]=='0'));

{

oxo[r0][c0]='0';

}

count++;

} display_grid();

/*These lines look to see if there is a row of 0s in any of the 8 ways
possible program looks to see if 0s have won*/

if ((oxo[1][1]=='0'&&oxo[1][2]=='0'&&oxo[1][3]=='0')||

(oxo[2][1]=='0'&&oxo[2][2]=='0'&&oxo[2][3]=='0')||
(oxo[3][1]=='0'&&oxo[3][2]=='0'&&oxo[3][3]=='0')||
(oxo[1][1]=='0'&&oxo[2][1]=='0'&&oxo[3][1]=='0')||
(oxo[1][2]=='0'&&oxo[2][2]=='0'&&oxo[3][2]=='0')||
(oxo[1][3]=='0'&&oxo[2][3]=='0'&&oxo[3][3]=='0')||
(oxo[1][1]=='0'&&oxo[2][2]=='0'&&oxo[3][3]=='0')||
(oxo[3][1]=='0'&&oxo[2][2]=='0'&&oxo[1][3]=='0'))

{

printf("\n GAME OVER...%s WINS.... GAME OVER\n",name1); / /*if 0 wins
print this*/

return; /*if '0' wins end game*/

}

else /*if 0 not won program continues*/

count<9;

if (count<9)

{

do{

printf("%s enter you next move, 'X's",name2 ; /*asks for m move by
name*/

scanf("%d%d",&rx,&cx);

}

while((oxo[rx][cx]!='.')||(oxo[rx][cx]=='X')||(oxo[rx][cx]=='0'));

{

oxo[rx][cx]='X';
}

count++;

}

display_grid();

/*These lines look to see if there is a row of Xs in any of the 8 ways
possible program looks to see if Xs have won*/

if ((oxo[1][1]=='X'&&oxo[1][2]=='X'&&oxo[1][3]=='X')||

(oxo[2][1]=='X'&&oxo[2][2]=='X'&&oxo[2][3]=='X')||
(oxo[3][1]=='X'&&oxo[3][2]=='X'&&oxo[3][3]=='X')||
(oxo[1][1]=='X'&&oxo[2][1]=='X'&&oxo[3][1]=='X')||
(oxo[1][2]=='X'&&oxo[2][2]=='X'&&oxo[3][2]=='X')||
(oxo[1][3]=='X'&&oxo[2][3]=='X'&&oxo[3][3]=='X')||
(oxo[1][1]=='X'&&oxo[2][2]=='X'&&oxo[3][3]=='X')||
(oxo[3][1]=='X'&&oxo[2][2]=='X'&&oxo[1][3]=='X'))

{

printf("\nGAME OVER...%s WINS!!... GAME OVER\n",name2);
/ /*if X wins print this*/

return; /*if X wins end game*/

}

else /*if 0 not won program continues*/

count<9;

}

if (count=9) /*when 9 moves have been made with no winner game stops*/

printf("\nGAME OVER...NO WINNER!!...GAME OVER\n"); /*print o u out*/

}

void display_grid()

{

int row, col;

for(row=1;row<=3;row++)

{

for(col=1;col<=3;col++)

{

printf(" %c |",oxo[row][col]); /*prints & spaces vertical g grid
lines*/

}

printf("\n");

if(row<=3)

{

printf(" ---------------\n"); /*prints & spaces horizontal g grid
lines*/

}

}

return;

}
A:
Dear *NAME-DELETED*,

The program you wrote works fine. There are some minor syntax errors that
you have to correct. Other than that there is no problem with the program,
and in case the program was written you I congratulate, because you wrote
functionally perfect code without debugging. To fix the syntax errors on
the other hand should not be an issue for you.

Please respect others to write English and not slang. Especially when you
talk to someone that is not native English as I am. It really caused me a
small hedeache to understand your sentences. I made me actually learn some
american slang, but that is not the purpose.

regards,
Peter
Q:
Sorry about the slang, the problem i am having is when I cut and paste the
program into the telnet window, when i compile the program i get errors,
and cant run the program, but when i run the program in linux it works
fine, do you know why this might be happening? Have you got access to
telnet so you can try? AGAIN, im am very sorry about the slang used in my
last post. (",)

A:
Dear Mark,

as I wrote in my last letter there are (were) some syntax errors in the
program that way you sent it to me. They do NOT seem to be simple
copy/paste errors, but rather typing errors. It would be helpful if you
could not only say that the compiler gives error but could verbatim copy
here the error messages, thus I could have some clue on the reason.

Regards,
Peter

[ back to toc ]