```1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 ``` ```//Kevin Fiol, 06/18/2012, Assignment 1: Letter Guessing Game, David Dittman #include #include #define MAX_GUESSES 5 //this function provides instructions to the user on how to play the game void Instructions( ); //this function runs one game. It checks for either 5 incorrect guesses or correct guess. //It returns a 0 if the game is over and the player did not guess the letter, otherwise it returns 1. int PlayGuess(char); //this function prompts the player to make a guess and returns that guess //this function is called from inside the PlayGuess( ) function described above char GetLetter(); //this function takes two arguments, the guess from the player //and the solution letter from the file. //It lets the user know if the guess comes alphabetically before or after the answer //The function returns 1 if the guess matches the solution and returns a 0 if they do not match int CompareLetters(char,char); //function prototypes //do not forget to add comments above the function ptototypes (see examples) //function Definitions //do not forget to add comments above the function definitions (see examples) int main() { //variable declarations int i = 0; int numGames = 0; int game; int numGuesses; int winOrLose; char guess; char solution; //file pointer declaration FILE *infile; //connect to the file infile = fopen("inputLet.txt", "r"); //display instructions Instructions(); //get number of games the user wants to play scanf("%d",&numGames); for(i=1; i <= numGames; i++) { //print current game (value of i) printf("Current game: %d\n", i); //get letter to guess from file fscanf(infile," %c", &solution); //call the playGuess function to play a game PlayGuess(solution); //it will return a 1 if the user wins and a 0 if the user took more than 6 guesses //condition here to print win or lose if(winOrLose == 0) { printf("You did not guess the letter\nThe letter you were looking for was %c",solution); } else if(winOrLose == 1) { printf("You guessed it!\n"); } } fclose(infile); return 0; } void Instructions() { printf("Welcome to Letter Guess!\n"); printf("You will enter the number of games you want to play (1-4 games)\n"); printf("You have five chances to guess each letter\n"); printf("Let's begin: How many games do you want to play?\n"); } int PlayGuess(char solution) { //variable declartations: numGuesses=0, winOrLose=0 int numGuesses = 0; int winOrLose = 0; char guess; while(numGuesses < MAX_GUESSES && winOrLose == 0) { //get the guess from the user (call GetLetter function) GetLetter(); //call compareLetters function CompareLetters(guess,solution); //update numGuesses numGuesses = numGuesses + 1; if(numGuesses > MAX_GUESSES) { printf("You have used up all your guesses!\n"); } } //return a 1 or a 0 after the loop //depending on whether the user one or lost that game if(guess != solution || numGuesses > MAX_GUESSES) { winOrLose = 0; return 0; } else if(guess == solution) { winOrLose = 1; return 1; } } char GetLetter() { //declare user's guess char guess; //get the users' guess scanf("Please enter a guess: %c",&guess); //change to lower case guess = tolower(guess); //return the users' guess return guess; } int CompareLetters(char guess, char solution) { //compare the guess and the solution //return a 1 if they are the same if(guess == solution) { printf("That's it!\n"); return 1; } //print a message based on before or after alphabetically //return a 0 if the guess and answer are not the same else if(guess > solution) { printf("The letter comes before %c, try again.\n",guess); GetLetter(); return 0; } else if(guess < solution) { printf("The letter comes after %c, try again.\n",guess); GetLetter(); return 0; } } ```
 ```1 ``` ```Segmentation fault ```