Run-time check failure

Run-Time Check Failure #3 - The variable 'displayword' is being used without being initialized.Please help someone hehe.

Last edited on
secretword[20]=displayword[20];

Two problems here. Firstly, you're using the variable displayword, but you have no idea what value it has. This is what the error means.

Secondly, an array of size 20 goes from element zero to element 19. There is no element 20. So this displayword[20] is off the end of the array and you're reading some other memory. This is bad.
Thanks for the quick reply. Now it says

Run-Time Check Failure #3 - The variable 'userguess' is being used without being initialized

updated code:



What I am trying to do is get the randomly selected word to display on the screen as "*"s instead of letters. But I know my structure sucks and my code leeks in-experience. Could you advise on that as well please?
Last edited on
On line 145, you are using userguess in the for loop but you haven't input anything to it yet, or initialized it. Therefore it contains undefined data. Also, not sure why you are using a char variable in the test expression anyway. Since chars are stored as ascii code, this expression will convert that code to an int and write * into display word well beyond what that array should hold. For instance, say the use input an 'a'. The decimal value of that is 97. So that test expression would be seen as i < 97. That means you'd be writing 87 more elements past the end of displayword[9].

As was mentioned, secretword[10] and displayword[10] are both outside the bounds of the char arrays, so that line does nothing useful and could in fact be a crash. The behavior is undefined in any case.
How have I not initialized userguess? It is char userguess at the top? Or do I need to do int userguess and if they input a character like "a" it will be converted to ascii code? i.e 97 as you said.

I have removed secretword[10] and displayword[10]

As for why:

The reason why userguess is in the equation is because I want the secretword to be displayed as asciis via displayword.

But because secretword is already a char, and this is where the random word is stored, would I need to make an int secretword?

Updated code for reference: (Only removed secretword[10] and displayword[10])

Last edited on
How have I not initialized userguess?


To initialise a variable is to give it a value.

char userguess; What is the value of userguess? What letter is it at the start?

char userguess is where the user's letter input goes.

Ahh I am an idiot. The for loop was before the variable got input.

Run-Time Check Failure #2 - Stack around the variable 'displayword' was corrupted.
Topic archived. No new replies allowed.