hangman need help with strings and pointers
I need some help with my code as I’m not very familiar with strings and pointers. I need to have 6 functions in my code. So far I have only written 3. I now need a function to
a) Check if the guessed letter is in the word
b) Compare the word after every guess with the inputted word.
The problem is I must use pointers to search the string and compare the strings
/* Program that uses pointers and functions to create a simple 2 player version of hangman. Player 1 enters a 9 letter word, which has to be guessed by player 2. The 9 letter word entered by player 1 is to be displayed initially using 9 asterisks(*). As a correct letter is guessed, it replaces the asterisk at its proper location in the word. 3 wrong guesses and player two loses. If player 2 completes the word with less than 3 wrong guesses, s/he wins. The user is given the choice of quitting or playing again after every go. */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXSIZE 9
void intro( );
void get_data (char *data);
char get_letter( );
void check_letter(char *data, char c, int * mistakes);
void output();
void main( )
{
char word[MAXSIZE], guess;
int miss = 0;
intro ( ) ;
get_data (data);
system("CLS");
while (miss < 3)
{
guess = get_letter();
check_letter(data, guess, &miss);
}
return 0;
}
/* FUNCTIONS*/
void intro()
{
printf(" ********************************************\n");
printf("Hangman \n");
printf(" ********************************************\n\n") ;
printf("Welcome to my game. Try to guess the word in the fewest possible goes. 3 wrong letter guesses and you lose! \n\n");
}
void get_data (char *data)
{
printf("Player 1, input 9 letter word for the other player to guess>");
scanf(“%c”, data)
while(data!=MAXSIZE)
{
printf(“ Error, invalid input. Enter a 9 letter word only\n”);
scanf(“%c”, data)
}
return data;
}
char get_letter( )
{
char c;
printf(“*********\n”);
printf(“Guess a Letter>\n”);
while ( getchar() != '\n' );
scanf ( "%c", &c );
return c;
}
void check_letter(char word[MAXSIZE], char c, int *mistakes)
{
int i = 0, m = 0, n = 0;
do
{
if (word[i] != c)
{
printf("*");
m += 1;
}
else
{
printf("%c", c);
n += 1;
}
i += 1;
}while(i <= strlen(word));
*mistakes = m;
printf("You uncovered %d letters\n\n", n);
Re: hangman need help with strings and pointers