LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Validation (https://www.linuxquestions.org/questions/programming-9/validation-20185/)

Makaveli.2003 05-04-2002 09:48 AM

Validation
 
At the moment my code looks like this: This code is taken from a noughts and crosses game
--------
display_grid();

count=0;

while(count<9)

{

if(count<9)

{

do{

printf("%s enter you next move, '0's\n",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++;

------
What I want it to do is recognize if a position on the board is already taken, I know this is the answer (below) but dont know how to re-work the loop and add the below code, ive tried a few things but it doesnt work.

if( r0 != -1 && c0 != -1 )
printf("The place is already occupied\n");



If you require more code it will be provided, just ask.

Thx

Mik 05-06-2002 08:30 AM

How about something like this:

Code:

bool valid = false;

while(!valid)
{
  printf("%s enter you next move, '0's\n",name1);
  /*asks for m move by name*/

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

  if (oxo[r0][c0] == '.')
  {
    valid = true;
    oxo[r0][c0]='0';
  }
  else
    printf("The place is already occupied\n");
}

The code does assume you have initialised all the empty places as the character '.'


All times are GMT -5. The time now is 09:53 PM.