LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-04-2002, 10:48 AM   #1
Makaveli.2003
LQ Newbie
 
Registered: May 2002
Location: England, UK
Posts: 5

Rep: Reputation: 0
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
 
Old 05-06-2002, 09:30 AM   #2
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 46
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 '.'
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Genuine Windows Validation microsoft/linux General 1 10-11-2005 11:43 PM
email address validation rblampain Linux - Security 8 09-21-2005 03:20 AM
Rule validation techniques for XML jwstric2 Programming 1 06-27-2005 12:32 AM
Partition corruption fix validation notb Linux - General 2 11-08-2004 10:54 AM
Confused trying to do password validation in PHP Pcghost Programming 4 02-02-2004 01:10 PM


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

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration