hw6p2.c - \/Kyle Yamamoto\/This program is hangman#define_CRT_SECURE_NO_WARNINGS#include<stdio.h> void print_word(char word char guess cfw\/Functio n to

hw6p2.c - /Kyle Yamamoto/This program is...

  • Homework Help
  • captain0cat
  • 3
  • 100% (3) 3 out of 3 people found this document helpful

This preview shows page 1 - 3 out of 3 pages.

//Kyle Yamamoto //10-16-2014 //This program is hangman #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> void print_word(char word[], char guess[]) { //Functio n to display the secret word int i = 0, j = 0; while (word[i] != NULL) { //While loop to see if letter is in word for (j = 0; j < 26; j++) { //For loop to see all guesses if (guess[j] == word[i]) { //If statement to print letter if picked printf("%c", word[i]); break; } } if (guess[j] != word[i]) { //If statement to print * if not picked printf("*"); } i = i + 1; } printf("\n"); } int guess_letter(char guess[], int try, char word[], int wrong) { //Function to identify missing letters int i = 0, counter = 0; printf("Guess a letter: "); scanf(" %c", &guess[try]); //User input for letter while (word[i] != NULL) { //Counts how many times that letter shows up if (guess[try] == word[i]) { counter = counter + 1; } i = i + 1; } if (counter == 0) { //If statement if there are no letters the same as the guess printf("Letter %c is not part of the secret word, You have %d tries left\n", guess[try], 5 - wrong); return 1; } printf("Letter %c was found %d times in the secret word\n", guess[try], counter); return 0;
Image of page 1
} int is_in(char guess[],char word[], int length) { //Functio n to identify if all the letters are guessed
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 3 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes