Question: This is for C program: I am trying to create the following program with the following functions. Already created a main.c and have the following

This is for C program: I am trying to create the following program with the following functions. Already created a main.c and have the following functions that need to run in my new program as the same as my main. Please help. I am new to this.

main.c

#include #include #include

int main() { FILE *fp; fp = fopen("game.txt", "r"); char **puzzles; int count = 0; int num = 0; int numWords = 0; int win = 0; int randomPuzzle; int i = 0; char letter; if ( fp != NULL ) { char line[30]; while ( fgets ( line, sizeof line, fp ) != NULL ) { size_t len = strlen(line); if (len > 0 && line[len-1] == ' ') { line[--len] = '\0'; } num++; if ( num == 1 ) { numWords = atoi(line); puzzles = malloc(sizeof (char) * (numWords)); num++; } else { puzzles[count] = malloc(sizeof (char) * 30); strcpy(puzzles[count], line); count++; } } } time_t t; char *hangman = "HANGMAN"; srand((unsigned) time(&t)); randomPuzzle = rand() % numWords; char *originalPuzzle = malloc(sizeof(char)*30); char *missedGuess = malloc(sizeof(char) *8); int curPuzLength = 0; int found = 0; int missedWord = 0; strcpy(originalPuzzle, puzzles[randomPuzzle]); curPuzLength = strlen(originalPuzzle); char *currentPuzzle = malloc(sizeof(char) *curPuzLength); printf("puzzle chosen => [%s] ", originalPuzzle); printf("Current Puzzle:"); for (i = 0; i < curPuzLength; i++) { strcat(currentPuzzle, "_"); } printf(currentPuzzle); printf(" Missed Guesses: "); for (i = 0; i < 7; i++) { strcat(missedGuess," "); } int missedCounter = 0; printf("Please guess a letter:"); scanf("%c",&letter); while (1) { found = 0; printf("Current Puzzle:"); for (i = 0; i < curPuzLength; i++) { if (letter == originalPuzzle[i]) { currentPuzzle[i] = letter; found = 1; } else if (currentPuzzle[i] == '_') { currentPuzzle[i] = '_'; } } printf("%s ",currentPuzzle); printf("Missed Guesses:"); if (found) { printf("%s ", missedGuess); } else { missedGuess[missedCounter] = hangman[missedWord]; missedWord++; missedCounter++; printf("%s ", missedGuess); } if (missedWord > 6) { printf("You LOST! "); printf("Exiting program... "); exit(0); } if ( strcmp(currentPuzzle, originalPuzzle) == 0 ) { printf("You WON! "); printf("Exiting program... "); exit(0); } printf("Please guess a letter:"); scanf("%1s",&letter); }

return 0; }

My functions:

#include

typdef struct Hangman

{

char **puzzles;

int numPuzzles;

char *currentPuzzleWord;

char *guessedWord;

bool gameOver;

bool gameWon;

int missedGuesses;

*Hangman;

}

Hangman createHangmanGame(char *puzzleFile)

void newHangmanPuzzle(Hangman currentHangmanGame)

void loadPuzzleFile(Hangman currentHangmanGame, char *puzzleFile)

bool isPuzzleOver(Hangman currentHangmanGame)

bool isPuzzleSolved(Hangman currentHangmanGame)

char* getGuessedWord(Hangman currentHangmanGame)

bool guessLetter(Hangman currentHangmanGame, char letterToGuess)

char* getStateOfHangman(Hangman currentHangmanGame)

void freeHangmanGame(Hangman currentHangmanGame)

My new main:

#include

#include

#include

typdef struct Hangman

int main(int argc, char** argv)

{

int i;

system("cls");

printf(" Welcome to the Hangman Game! ");

printf(" You will have 7 chances to guess the right word. ")

getchar();

printf(" Hit >> ENTER<<");

system("cls");

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!