# Thread: undetected problem

1. ## undetected problem

Code:
```it compiles but im really unable to find the problem

int already_guessed(char dothenta[ALPHABET], char *letter ){
int i;
printf("You have guessed that. Give me a new letter:");
putchar('{');
for(i=0;i<ALPHABET && dothenta[i]!=' ';i++)
printf(" %c ",dothenta[i]);
putchar('}');
scanf("%c",*&letter);
return 1;

}
char  ekt_arith_kai_diav(int counter,char dothenta[ALPHABET]){
char letter;
int i;
printf("Give me a letter { ");
for(i=0;i<counter && dothenta[i]!='\0';i++)
printf("%c",dothenta[i]);
putchar('}');
scanf("%c",&letter);
putchar('\n');
return letter;

}
void print_word(int thesi, char Dict[MaxWords][MaxWordLen],char guess[30]){
int i;
printf("The word is: ");
for(i=0;i<MaxWordLen && Dict[thesi][i]!='\0';i++)
guess[i]=('-');
for(i=0;i<MaxWordLen && Dict[thesi][i]!='\0';i++)
printf("%c",guess[i]);
putchar('\n');

}

switch (choice){

case 1:		counter=0;
thesi=Random(0,NumWords,&seed);
print_word(thesi,Dict,guess);	//tiponi leksi
for (i=0;i<ALPHABET;i++)
dothenta[i]='\0';	//arxikopoihsi
alaxe=0;
do{
if (!already_answered)
letter=ekt_arith_kai_diav(counter,dothenta);
do{
for(i=0;i<=counter && dothenta[i]!='\0';i++)
if ( letter!=dothenta[i] )
mem=1;
else{
mem=0;
already_answered=already_guessed(dothenta,&letter);
break;
}
}while(!mem);
dothenta[counter]=letter;
counter++;
for(i=0;i<MaxWordLen && Dict[thesi][i]!='\0';i++)
if (Dict[thesi][i]==letter){
guess[i]=letter;
alaxe=1;
}
if(!alaxe)
fail++;
vrike=elenx_an_vrike_leksi(Dict,guess,thesi);
if (vrike){
you_have++;
WellDoneMsg();
}
else if (fail==7){
i_have++;
SorryMsg(Dict[thesi]);
}
}while(fail!=7 && !vrike);
break;

i didnt put the other functions because there were already made my the teacher
what the problem is?
when im choosing the first option (case 1)
it shows
Give me a letter { }
Give me a letter {
}
than Give me a letter { } and to wait for my answer```

2. noone?

3. Seems like you have data in the input buffer that's leftover from a previous input operation... probably a stray newline that you need to get rid of. If the previous input operation was something like a scanf with a %d format specifier, then the trailing newline is very much likely still in the input buffer and when your code gets to that scanf("%c",&letter) part, it read the newline and continues on with the rest of the code without stopping to let you enter the letter. You need to clear the input buffer of that whitespace and the easiest way of doing that is to put a space in front of the %c in that scanf call. The space tells the scanf to ignore leading whitespace.
Code:
```char  ekt_arith_kai_diav(int counter,char dothenta[ALPHABET]){
char letter;
int i;
printf("Give me a letter { ");
for(i=0;i<counter && dothenta[i]!='\0';i++)
printf("%c",dothenta[i]);
putchar('}');
scanf(" %c",&letter);  /* Notice the space */```

Popular pages Recent additions