Author: Dann Corbit
Date: 00:12:43 01/11/03
Go up one level in this thread
On January 11, 2003 at 01:26:57, Joshua Haglund wrote:
>Hi
>
>I need some clarification with a piece of code.
>
><snip>
>
>string menuChoice = " ";
>
> menuChoice = displayMenu();
> while (menuChoice != "exit")
> {
> if (menuChoice == "xboard")
> xboard();
> else if (menuChoice == "log")
> log();
> else if (menuChoice == moves[5]) <---right here with moves[5],
> moves();
> else
> cout << "Invalid move." << endl;
>
><snip>
>
>IF moves(); looked like this:
>
>void moves() {
>
>string moves[5] {"e2e4", "d2d4", "Nf3", "f2f4", "c2c4"};
>}
>
>What I want to do is:
>
>if I enter a string for example:
>
>White(1): e2e4
>
>I want to have moves(); to look _in_ the string array move[5] and look for
>"e2e4"
>and if it finds "e2e4" selecting it for further processes. I'm not sure if i'm
>going about this the right way.
>
>else if (menuChoice == moves[5]) <---- I want to look in moves[5] for a string.
>
>Looking for some clarification,
In that array, the biggest allowed index is 4, because that is the 5th element.
strcmp() will find it.
Assuming:
char * moves[5] = {"e2e4", "d2d4", "Nf3", "f2f4", "c2c4"};
Then:
moves[0] = "e2e4";
moves[1] = "d2d4";
moves[2] = "Nf3";
moves[3] = "f2f4";
moves[4] = "c2c4";
The five elements are numbered 0 to 4.
This page took 0 seconds to execute
Last modified: Thu, 15 Apr 21 08:11:13 -0700
Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.