Here's the solution:
Code:
bool isValid(char s[])
{
return hasOnly(s, "xyz") && endsWith(s, 'z') && comesAttached(s, 'y') && countChar(s, 'x') % 2 != 0;
}
I leave the implementation of the functions called as an exercise to the reader, but my point here is that if you break up the problem into smaller parts, then it can become easier to solve and debug. A trade-off is that it could also be less efficient, but if the difference is negligible for your purposes, then the gain outweighs the cost.
Incidentally, the implementation of hasOnly is trivial if you are allowed to use strspn from <string.h>.