Guest_imported
New member
- Jan 1, 1970
- 0
i am trying to write a C program for a very simple hangman game which uses just one word 'mouse' assumes there is no repeat characters er with graphics. The basic layyout will be ----- for the letters of the word then user will be asked to guess letter and as they are guessed correctly will be revelaed in the correct "-". I dont want this program to involve any strings, just arrays and functions.
The code i have below so far accpets the user input of a letter but it is not registering when the letter is correect. Also Im having problems with how to assign the correct letter to the correct dash. I know this will involve another array guess_word[5] = {'-','-','-','-','-'} but does anyone have any idea how i would go about assigning the letters to there correct spaces?
Any help would be gratefully accepted im really in a hole here!!
#include <stdio.h>
#define letters 5
int search(const char list[], int letternum, char letter);
int main(void)
{
char word[letters] = {'m','o', 'u', 's', 'e'};
char letter;
int location;
int tries = 0;
do
{
printf("choose a letter: "
;
scanf("%1s", &letter);
location = search(word, letters, letter);
if (location) printf("%c was found\n", letter);
else printf("%c was not found\n", letter);
++tries;
}while(tries < 6);
return 0;
}
int search(const char list[], int letternum, char letter)
{
int i = 0, found = 0;
while (i < letternum && !found)
{
if (list == letter) found = 1;
else i++;
}
return found;
}
The code i have below so far accpets the user input of a letter but it is not registering when the letter is correect. Also Im having problems with how to assign the correct letter to the correct dash. I know this will involve another array guess_word[5] = {'-','-','-','-','-'} but does anyone have any idea how i would go about assigning the letters to there correct spaces?
Any help would be gratefully accepted im really in a hole here!!
#include <stdio.h>
#define letters 5
int search(const char list[], int letternum, char letter);
int main(void)
{
char word[letters] = {'m','o', 'u', 's', 'e'};
char letter;
int location;
int tries = 0;
do
{
printf("choose a letter: "
scanf("%1s", &letter);
location = search(word, letters, letter);
if (location) printf("%c was found\n", letter);
else printf("%c was not found\n", letter);
++tries;
}while(tries < 6);
return 0;
}
int search(const char list[], int letternum, char letter)
{
int i = 0, found = 0;
while (i < letternum && !found)
{
if (list == letter) found = 1;
else i++;
}
return found;
}