I am new to C++ and I have a two player word guessing game working well. However, I would like to be able to validate whether the word entered by player 1 is a completely alphabetic word using isalpha.
The error I am getting right now is as follows:
"error: array must be initialized with a brace-enclosed initializer
char str[100]=hiddenwordtwo;"
Can someone help with this? I have been reading all over the place, but I have no idea how to fix this. I would really appreciate it! This is the relevant portion of my code:
int main ()
{
char hiddenwordtwo[100];
string hiddenword;
strcpy(hiddenwordtwo,hiddenword.c_str());
hiddenword=hiddenwordtwo;
cout << "Welcome to the 2-player word guessing game!" << endl;
cout << "\nPlayer 2 please look away from the screen"
<< "\nPlayer 1 please enter any word: " << endl;
cin >> hiddenword;//player 1's entry
int i=0;
char str[100]=hiddenwordtwo;
while (str[i])
{
if (isalpha(str[i])) printf ("character %c is alphabetic\n",str[i]);
else printf ("character %c is not alphabetic\n",str[i]);
i++;
}
return 0;
}