Hi everyone, sorry for the late question
I have to submit a hangman and i have a problem when the word of the hangman has special characters, during the test the word is : #dnfé_t@xt # 1 _ @ i v f m a t and it's the only part that fails. Where does it come from ?
Thanks alot would help me so much. (same when some letters of this word are CAPS)
Hi,
Thanks for your answer. Well the hangman.h was given by the tutor, we only had to include it and therefore should be correct. Same for tests.h wich is an automatic test from the Tutor where i got the error when he tested special character words. I looked through my code several times but cant find why it doesnt work properly as soon as you get special character combinations.
Thanks Marcus
Yeah thanks that helped me to find where the problem occurs. In fact the test runs the code and compares if the output answer is what is expected. The problem is when the computer choses the word : #inf1_m@vt # 1 _ @ A B C D E F G or #inf1_m@vt # 1 _ @ i n f m v t
the code only detects a word of 10 characters beacuse 11th one is a blank. Therefore the computer finds the 10 character word and answers : You won ! Word was #inf1_m@vt because the end is not detected as part as the word.
it should detect the whole #inf1_m@vt # 1 _ @ i n f m v t as secret word and not only until the first blank. Anyways i cannot figure out how to make it read past the blank spaces.
And yes é is also a problem but it's written i should count accents and other ''unusual punctuation like ö etc... "
here is what i got about the function:
the chooseWord() function:
std::string word_to_guess = chooseWord();
which returns a random English word (from a predefined list) as a string. The latter is more fun since you can play against the computer this way.
Thanks alot
if you don't want to discard white-spaces, use this
cin.get(inchar);
cin has a flag that by default, tells it to discard whitespace. so if you want to continue using
cin >> inchar;
you need to unset said flag, so that cin won't skip whitespaces anymore.
As you can read here -> http://www.cplusplus.com/reference/ios/ios_base/
ios_base:
Base class for the entire hierarchy of stream classes in the standard input/output library, describing the most basic part of a stream which is common to all stream objects, independently of their character type.
as you can see in that page, there is a function "unsetf" thas is meant to unset a flag in a stream such as cin.
So you need to #include <iomanip> and call cin.unsetf(ios::skipws);
so that cin won't discard whitespaces anymore. You can read the rest of the possible flags here:
http://www.cplusplus.com/reference/ios/ios_base/fmtflags/