If you're looping through all the characters in the word in your for loop, valid_word will have the result of only the last character. It gets overwritten every time the loop iterates. I think you'd want to stop checking once you find an invalid character (or you reach the end of the word without finding an invalid character).
If this function returns true/false, you could make it a bool function and define valid_word as a bool type. (Keeping in mind with bool that 0 is false, 1 is true, which is the opposite of what you have defined now).
bool valid_word = true; // Assume valid until determined otherwise
for (i=0; i<x; i++)
{ if (! isalpha(word_playerA[i]))
{ valid_word = false;
break; // no need to check further
}
}
BTW, why are you passing i as an argument? i should be a local variable.
That looks flash!! but i cannot use it since we didn't learn it.
It need to be a loop similar to mine, that is the reason its harder to put your head around that way. I think im almost there,
I need to find a way to hold the value of valid_word.
Or do a bool type, but im not sure how to do it in C. I cant use C++
I was bringing i to the function to make the loop, but i've changed to a local variable, it makes more sense..
Lines 6-9 serve no purpose. You initialize valid_word to 0. You then check the first character for a valid letter and sets valid_word to 0. This changes nothing.
I'm really unsure what you're trying to do in lines 13-21. It looks like you're trying to set j to 0 if a character is valid. Then you compare that flag to valid_word.
Your use of 0 and for j and valid_word is unconventional. Usually 0 = false and 1 = true. You're using those values the other way around, which is confusing.
A simple variation of what I posted earlier should work in C.
1 2 3 4 5 6
int valid_word = 1; // Assume valid until determined otherwise
for (i=0; i<x; i++)
{ if (word_playerA[i] < 'a' || word_playerA[i] > 'z')
valid_word = 0; // found invalid character
}