I'm a student and taking an intro to C class and would appreciate some help!
I've got a file with 10 words that I've loaded into a 2D array. I've written code that will generate a random number between 0 and 9 to select a string from the array. I'm using random_word for this variable
I ask the user to guess a single letter which they think may be in the string selected. I'm using guess for that variable
I'm trying to write a function that takes the randomly selected string in the array and checks the guess that the user input.
My code compiles but when I get to the part where it asks the user to input the character they would like guess, the program just hangs after I've typed a single character and hit return.
int findchar(char words[][ARRSIZE], char guess, int random_word){
int i;
while(words[random_word] != '\0'){
if(words[random_word] == guess)
return 1;
}
return -1;
}
Once the function is run I'm expecting it to return a 1 or a -1 which I check with these if statements.
is_letter = findchar(words, guess, random_word);
if(is_letter == -1){
printf("%c, is not there!\n", guess);
}
else if(is_letter == 1){
printf("There is a %c in this word!\n", guess);
}