Question
Please explain on each code to make me understand the code. please do not declare text.txt file and other variables as global. Please create a
Please explain on each code to make me understand the code.
please do not declare text.txt file and other variables as global.
Please create a struct. Everything need to be local except defining words length.
declare text.txt file in a function a function then pass it.
Double check and follow the instruction and will downvote if the code does not meet the requirement.
Output sample:
The output will a little bit different because I can not copy everything in the text.txt file.
As long as you follow the step, we will recieve an upvote.
Test input and output:
text.txt
abby abc abcess abcissa abcoulomb
abdominogenital abdominohysterectomy abdominohysterotomy abdominoposterior abdominoscope abdominoscopy abdominothoracic abdominous abdominovaginal abdominovesical
acecaffine aceconitic aced acedia acediamin acediamine
lowerable lowercase lowerclassman lowerclassmen lowered lowerer lowering loweringly loweringness lowermost lowers lowery lowes
preenlist preenlistment preenlistments preenroll preenrollment preens preentail preentailment preenter preentertain preentertainer preentertainment preenthusiasm preentitle preentitled preentitling preentrance preentry preenumerate preenumerated preenumerating
socialization socializations socialize socialized socializer socializers socializes socializing socially socialness socials sociate sociation sociative socies societal societally societarian societarianism societary societasYou will be creating a C program that will allow the user to play this game. We will allow the user to play with words of various lengths, not just 4-letter words. Running the Program The program begins by displaying a message to introduce the game. It then asks the user to enter the number of letters that they would like the words in the game to have. All the possible words can be found in the words . txt file. The words are listed there in alphabetical order, and are of varied lengths. Then, there should be output to indicate the number of words of that length which were found in the file. Because the number of words of that length is unknown, your program should use dynamic array allocation to create space and store the words of the length specified by the user. (You may use fixed-size arrays for other purposes.) - Use of a fixed-size array for the words of the user-specified length will result in a 25-point deduction. Also be sure that your program does not result in any memory leaks! - To practice dynamically growing an array, you should not go through the file first to count the number of words, and then create an array. Your program should dynamically grow the array as you read through the file and need more space to store the words. If you use malloc() to create space for the array but do not dynamically grow the array. this will result in a 10-point deduction. Weaver is a game where you try to find a way to get from the starting word to the ending word. You can change only one letter at a time, and each word along the way must be a valid word. Enjoy! How many letters do you want to have in the words? 4 Number of 4-1etter words found: 7186. At this point, the user may choose to enter the starting or ending words, or type ' r ' to select a random word from the words available: Weaver is a game where you try to find a way to get from the starting word to the ending word, You can change only one letter at a time, and each word along the way must be a valid word. Enjoy! How many letters do you want to have in the words? 4 Number of 4-letter words found: 7186 . Enter starting and ending words, or ' r ' for either for a randon word: songs sink Your word, "songs', is not a 4-letter word. Try again. Enter starting and' ending words, or ' r ' for elther for a randon word: song sinks Your word, "sinks', is not a 4-letter word. Try again. Enter starting and' ending words, or ' r ' for either for a randon word: 22z2 aahs Your word, '22z2', is not a valid dictionary word. Try again. Enter starting and ending words, or ' r ' for either for a randon word: aahs 2z2z Your word, '2z2z', is not a valid dictionary word. Try again. Enter startine and ending words, or ' r ' for either for a randon word: aahs 222222 Your word, "zzzzzz', is not a 4-letter word. Try again. Enter starting and ending words, or ' r ' for either for a randon word: song sink Your starting word is: song. Your ending word is: sink. On each move enter a word of the sane length that is at most 1 character different and is also in the dictionary. You may also type in " q " to quit guessing. As shown in the above example, if the user tries to select a word, your program must validate that the word is the correct length and that it is in the dictionary, i.e. the words available from the file. Until these conditions are met, the user must try again. If both conditions are unmet, e.g. "zzzzzz" in the example above, the message for the correct length takes precedence. The user may also choose to have a random word for either the starting or ending word, or both: Enter starting and ending words, or ' r ' for either for a random word: r think Your starting word is: seedy. Your ending word is: think. How many letters do you want to have in the words? 6 Number of 6-letter words found: 29874. Enter starting and ending words, or ' r ' for either for a random word: trials skips Your word, 'skips', is not a 6-letter word. Try again. Enter starting and ending words, or ' r ' for either for a random word: trials r Your starting word is: trials. Your ending word is: tampoe. How many letters do you want to have in the words? 4 Number of 4 -letter words found: 7186. Enter starting and ending words, or ' r ' for either for a random word: r r Your starting word is: wugg. Your ending word is: kari. Random number generators are not really random. When developing your program it can be helpful to always have it make the same choices you run the program. To make this happen you need to seed the random number generator with a fixed value. You should only seed the random number generator once in your program, typically near the beginning of main(). That statement will look like: srand ( 1); Be sure that you include srand(1) only once at the beginning of main() when you submit your program! Otherwise, your output will not match the expected output. (If you would like different numbers each time, you may use srand(time(0)); ) To get a random number, you will likely want to have something like the following: rand () : numberofpossibleWords Once the user has been presented with the starting and ending words, they can play the game! Prompt them to enter their next word, and continue until they have successfully transitioned to the ending word or until they type ' q ' to quit. See an example below: How many letters do you want to have in the words? 4 Number of 4-letter words found: 7186. Enter starting and ending words, or " r ' for either for a random word: sung sink Your starting word is: sung. Your ending word is: sink. On each move enter a word of the same length that is at most 1 character different and is also in the dictionary. You may also type in ' q ' to quit guessing. 1. Previous word is "sung". Goal word is "sink". Next word: sings Your word, "sings", is not a 4-letter word. Try again. 1. Previous word is "sung". Goal word is 'sink'. Next word: ssss Your word, " 5555 ', is not a valid dictionary word. Try again. 1. Previous word is 'sung". Goal word is 'sink'. Next word: sink Your word, 'sink', is not exactly 1 character different. Try again. 1. Previous word is "sung". Goal word is 'sink'. Next word: ssssss Your word, "ssssss', is not a 4-letter word. Try again. 1. Previous word is "sung" . Goal word is 'sink'. Next word: sing 2. Previous word is "sing". Goal word is 'sink". Next word: sink Congratulations! You changed 'sung' into 'sink' in 2 moves. There are a few things that you need to check when the user enters their next word (listed in order of precedence): - The word should be the correct number of characters in length. - The word should be in the dictionary of valid words. - The word should have exactly one character different from the previous word. Note that the move number does not update unless the word entered meets all of the above conditions. The program prints a congratulations message when the user successfully changes the starting word into the ending word. The user may also type ' q ' if they would like to quit guessing, and no message is printed but it stops prompting the user for their next word: Enter starting and ending words, or " r " for either for a randon word: chip monk Your starting word is: chip. Your endine word is: monk. On each move enter a word of the sane length that is at most 1 character different and is also in the dictionary. You may also type in " q " to quit guessing. 1. Previous word is "chip". Goal word is "monk". Next word: chup Your word, "chup', is not a valid dictionary word. Try again. 1. Previous word is "chip". Goal word is 'monk". Next word: shap Your word, "shap', is not exactly 1 character different. Try again. 1. Previous word is "chip", Goal word is "monk". Next word: chap 2. Previous word is "chap", Goal word is "monk". Next word: chat 3. Previous word is "chat'. Goal word is 'monk". Next word: coat 4. Previous word is 'coat'. Goal word is 'monk'. Next word: moat 5. Previous word is "noat'. Goal word is 'monk". Next word: mont 6. Previous word is "mont". Goal word is 'monk". Next word: q In either case, once the user is done guessing, the program presents the following three menu options: Enter: 1 to play again, 2 to change the number of letters in the words and then play again, or 3 to exit the program. Your choice > If the user selects 1 , they are asked again to enter starting and ending words or have them selected at random, and they can play again. If the user selects 2, they are asked again how many letters they would like to have in the words used in the game, and then to enter the starting and ending words. If the user selects 3 , the program stops executing. Sample output is provided at the end of this document to see what this looks like. How many letters do you want to have in the words? 4 Number of 4 -letter words found: 7186. Enter starting and ending words, or 'r' for either for a random word: word r Your starting word is: word. Your ending word is: wugg. On each move enter a word of the same length that is at most 1 character different and is also in the dictionary. You may also type in ' q ' to quit guessing. 1. Previous word is 'word'. Goal word is 'wugg'. Next word: worg Your word, 'worg', is not a valid dictionary word. Try again. 1. Previous word is 'word'. Goal word is 'wugg'. Next word: words Your word, 'words', is not a 4-letter word. Try again. 1. Previous word is 'word'. Goal word is 'wugg'. Next word: wor Your word, 'wor', is not a 4-letter word. Try again. 1. Previous word is 'word'. Goal word is 'wugg'. Next word: hord Your word, 'hord', is not a valid dictionary word. Try again. 1. Previous word is 'word'. Goal word is 'wugg'. Next word: q Enter: 1 to play again, 2 to change the number of letters in the words and then play again, or 3 to exit the program. Your choice >1 Enter starting and ending words, or 'r' for either for a random word: song sinks Your word, 'sinks', is not a 4-letter word. Try again. Enter starting and ending words, or 'r' for either for a random word: songs sink Your word, 'songs', is not a 4-letter word. Try again. Enter starting and ending words, or 'r' for either for a random word: sonf sink Your word, 'sonf', is not a valid dictionary word. Try again. Enter starting and ending words, or 'r' for either for a random word: song sink Your starting word is: song. Your ending word is: sink. On each move enter a word of the same length that is at most 1 character different and is also in the dictionary. You may also type in ' q ' to quit guessing. 1. Previous word is 'song'. Goal word is 'sink'. Next word: sing 2. Previous word is 'sing'. Goal word is 'sink'. Next word: sint Your word, 'sint', is not a valid dictionary word. Try again. 2. Previous word is 'sing'. Goal word is 'sink'. Next word: sine 3. Previous word is 'sine'. Goal word is 'sink'. Next word: snips Your word, 'snips', is not a 4-letter word. Try again. 3. Previous word is 'sine'. Goal word is 'sink'. Next word: sink Congratulations! You changed 'song' into 'sink' in 3 moves. Enter: 1 to play again, 2 to change the number of letters in the words and then play again, or 3 to exit the program. Your choice >2 How many letters do you want to have in the words? 5 Number of 5 -letter words found: 15920. Enter starting and ending words, or ' r ' for either for a random word: think prink Your starting word is: think. Your ending word is: prink. On each move enter a word of the same length that is at most 1 character different and is also in the dictionary. You may also type in ' q ' to quit guessing. 1. Previous word is 'think'. Goal word is 'prink'. Next word: phink Your word, 'phink', is not a valid dictionary word. Try again. 1. Previous word is 'think'. Goal word is 'prink'. Next word: trink 2. Previous word is 'trink'. Goal word is 'prink'. Next word: trick 3. Previous word is 'trick'. Goal word is 'prink'. Next word: prick 4. Previous word is 'prick'. Goal word is 'prink'. Next word: pricks Your word, 'pricks', is not a 5-letter word. Try again. 4. Previous word is 'prick'. Goal word is 'prink'. Next word: prink Congratulations! You changed 'think' into 'prink' in 4 moves. Enter: 1 to play again, Your word, 'paleer', is not a valid dictionary word. Try again. 1. Previous word is 'palier'. Goal word is 'trials'. Next word: q Enter: 1 to play again, 2 to change the number of letters in the words and then play again, or 3 to exit the program. Your choice 1 Enter starting and ending words, or ' r ' for either for a random word: candle trials Your starting word is: candle. Your ending word is: trials. On each move enter a word of the same length that is at most 1 character different and is also in the dictionary. You may also type in ' q ' to quit guessing. 1. Previous word is 'candle'. Goal word is 'trials'. Next word: canele Your word, 'canele', is not a valid dictionary word. Try again. 1. Previous word is 'candle'. Goal word is 'trials'. Next word: q Enter: 1 to play again, 2 to change the number of letters in the words and then play again, or 3 to exit the program. Your choice >1 Enter starting and ending words, or ' r ' for either for a random word: thought r Your word, 'thought', is not a 6-letter word. Try again. Enter starting and ending words, or ' r ' for either for a random word: r thoughts Your word, 'thoughts', is not a 6-letter word. Try again. Enter starting and ending words, or ' r ' for either for a random word: candle trialz Your word, 'trialz', is not a valid dictionary word. Try again. Enter starting and ending words, or ' r ' for either for a random word: trialz candle Your word, 'trialz', is not a valid dictionary word. Try again. Enter starting and ending words, or ' r ' for either for a random word: r r Your starting word is: guards. Your ending word is: vocoid. On each move enter a word of the same length that is at most 1 character different and is also in the dictionary. You may also type in ' q ' to quit guessing. 1. Previous word is 'guards'. Goal word is 'vocoid'. Next word: vuards Your word, 'vuards', is not a valid dictionary word. Try again. 1. Previous word is 'guards'. Goal word is 'vocoid'. Next word: trials Your word, 'trials', is not exactly 1 character different. Try again. 1. Previous word is 'guards'. Goal word is 'vocoid'. Next word: guards Your word, 'guards', is not exactly 1 character different. Try again. 1. Previous word is 'guards'. Goal word is 'vocoid'. Next word: guardd Your word, 'guardd', is not a valid dictionary word. Try again. 1. Previous word is 'guards'. Goal word is 'vocoid'. Next word: q Enter: 1 to play again, 2 to change the number of letters in the words and then play again, or 3 to exit the program. Your choice 3 Thanks for playing! Exiting... Test Input: 4 r r 3
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started