View Full Version : Something to do with character conversion, I just can not figure it out.

4th November 2010, 22:28
The program should accept the input, find to see if it is in the word, then replace the null character _ with the correct letter.

char Guess[15];
guess looks like this, depending on word size

_ _ _ _ _

void hangman::guessed()
char Letter;
int Correct=0;
QString tochar;

tochar = ui->lineEdit->text();

QByteArray foo = tochar.toLatin1();

char *letter = foo.data();

Letter = *letter;

// Loop through the word
for(Subscript = 0; Subscript < Size; Subscript++)

//if the guess is good tell the user and update Guess
if(copy.at(Subscript) == Letter)


Guess[Subscript] = Letter;
Correct = 1;

instead of proper output like, _ _ e _ _
the textbox gets this appended to it.

ð*º`è_ ¸Ñ¦ ««««««««îþîþ

I feel as though its clearly a failed data conversion, I just do not know what to attempt next.

4th November 2010, 22:40
Lots of pointer confusion occurring here. I don't understand why you're using pointers in the first place; the conversions between Qt string/character objects and C-style strings is certainly part of what's causing your problem.

You ought to be able to write this routine entirely with QStrings and the functionality they provide. It's never a good idea to convert back and forth between different data representations unless there's no other way to accomplish something.