# Thread: Guess word Problem

1. ## Guess word Problem

hello there, i got problem with my code, when i starting to guess a letter and hit the enter, the letter i've guess is not printing in the blank i made. can someone help me to fix the code? thanks.

Code:
```int main(){
int i;
int j;
int x=0;
char word[30];
char undscr[30];
char length;
char letter;

printf("enter a word: ");
gets(word);

length=strlen(word);
undscr[x]='_';
for(i=0;i<length;i++)
{
printf(" %c", undscr[x]);
}

printf("\n\nguess the letter: ");
scanf("%c", &letter);
for(j=0;j<i;j++)
{
if(letter==word[i])
{
undscr[i]=word[i];
}
}

getch();
return 0;
}```

2. reply for this please, i really need your help.

3. Try this:
Code:
```#include <stdio.h>
#include <string.h>
#include <conio.h>

int main(){
int i;
int done=0;
int good=0;
char word[30];
char undscr[30];
char length;
char letter;

_gotoxy(1,3);
printf("enter a word: ");
gets(word);

length=strlen(word);
for(i=0;i<length;i++) {
undscr[i]='_';
}
while(!done) {
_gotoxy(1,5);
for(i=0;i<length;i++)
{
printf("%c ", undscr[i]);
}
if(good>=length) {
done=1;
break;
}

printf("\n\nguess the letter: ");
letter=_getch();
printf("%c",'\b');

for(i=0;i<length;i++)
{
if(letter==word[i])
{
undscr[i]=word[i];
good++;
}
}
}
_gotoxy(1,9);
if(done)
printf("You guessed it!\n\n");
printf("Hit Enter When Ready\n");
getchar();
return 0;
}```

4. Originally Posted by Adak
Try this:
Code:
```#include <stdio.h>
#include <string.h>
#include <conio.h>

int main(){
int i;
int done=0;
int good=0;
char word[30];
char undscr[30];
char length;
char letter;

_gotoxy(1,3);
printf("enter a word: ");
gets(word);

length=strlen(word);
for(i=0;i<length;i++) {
undscr[i]='_';
}
while(!done) {
_gotoxy(1,5);
for(i=0;i<length;i++)
{
printf("%c ", undscr[i]);
}
if(good>=length) {
done=1;
break;
}

printf("\n\nguess the letter: ");
letter=_getch();
printf("%c",'\b');

for(i=0;i<length;i++)
{
if(letter==word[i])
{
undscr[i]=word[i];
good++;
}
}
}
_gotoxy(1,9);
if(done)
printf("You guessed it!\n\n");
printf("Hit Enter When Ready\n");
getchar();
return 0;
}```
[Linker error] undefined reference to `gotoxy' , im using dec c++ as a compiler.

5. Remove the underscore from in front of _gotoxy's. gotoxy() is part of conio.h, but my compiler uses the leading underscore for it nowadays.

6. Originally Posted by Adak
Remove the underscore from in front of _gotoxy's. gotoxy() is part of conio.h, but my compiler uses the leading underscore for it nowadays.
its working thanks!!...

7. but its only works in TurboC not in DevC++.

8. Does Dev C support the conio.h include file? Do you have a conio.h file in your header file directory?

I don't have Dev C, so i can't help you with those problems.

If you are using Windows, you can use SetConsoleCursorPosition(), (you may have to include "windows.h"), instead of gotoxy(), but I'm not sure how to get a key stroke like getch(), in Windows. You can also skip the gotoxy() and getch(), and make it either a "rolling" screen presentation of the game input and output, or clear the screen between letters being entered. That will give the game a bit of a "blinking" look, but it might be OK.

I have heard that NCurses supports a lot of the same functions that conio.h does, but I haven't used it myself.

Popular pages Recent additions