string game_play()
{
char word[25];//Creates memory for the word that is to be guessed
char blank[25];//creates blank spaces
char guess;
cout<<player_one()<<" please enter a word or phrase with 25 or less characters"<<endl;
int counter=0; //simple counter
int correct=0;//1=correct answer, 0=wrong answer
cin.getline (word,25);
strlen(word);
cout<<"The word is "<<strlen(word)<<" characters long!"<<endl;
int length=strlen(word); //stores the length of the word or phrase
for (counter = 0; counter < length; counter++)//converts the letters to uppercase
{
word[counter] = toupper(word[counter]);
}
strcpy(blank,word);//Copies the word to the 'blank' array
for (counter = 0; counter < length; counter++)
{
if (isalnum(word[counter])) blank[counter] = '_'; //converts characters to _'s to represent blanks
else blank[counter] = word[counter];
}
char player_two[20];
cout<<"Player 2 please enter your name"<<endl;
cin>>player_two;
cin.get();
//play game until the 'blank' puzzle becomes the 'right' answer
do {
cout<<"The current blank puzzle is: "<<blank<<"."<<endl;
cout<<player_two<<" enter a guess."<<endl;
cin>>guess;
guess = toupper(guess);
for (counter = 0; counter <= length; counter++) //check guess
{
if (guess == word[counter])
{
blank[counter] = guess; //fill in the puzzle with the letter
}
}
}
while (word != blank);
cout<<"Winner!";
cin.get();
}
This a VERY common mistake. What you have to remember is that the name of a string is actually the address of that string.
What you are doing is saying
"while the address of word is the same as the address of blank, do this"
Those addresses will never be the same, since the actual location of the strings in memory will always be different.
Try using the strcmp() function to compare the two strings, the return value will be 0 if the two strings are the same.
edit...
oops, answered too late.