Coding Assignment 6 | Reliable Papers

Coding Assignment 6The format and content of the output are not suggestions – they are the specification given to you to follow so please followthem. Points will be lost for not following the specification. This includes using the specified functions. This is essential to thegrading process. If the assignment says to use strchr(), then please use strchr() and not some other way of achievingthe same result. The rubric is very specific and your code will be graded very specifically. This assignment is written the way itis to exercise the concepts we have been learning in class.Please watch the videos showing the game being played and examine the sample output provided in this document.Understanding how to play the game before studying this specification will be helpful. After watching the game being played,read this specification and then watch the video called “Coding Assignment 6”.Using the file name passed on the command line, your program will read a file and place the information from the file into anarray of structures where you will dynamically allocate the memory to store the file’s information. You are then using thatinformation to play the game. If you play the game and win, the winning entry is removed from the file so if you play again,you do not see the choice you already guessed.Your goal should be to change as little code as possible – don’t change it if you don’t need to.FOR THIS ASSIGNMENT, YOUR CODE WILL BE GRADED ON OMEGA (NOT THE VM).Note that the version of C on Omega is older and does not allow some of the newer C constructs. You are also required tohave a blank line at the end of every .c file – not having one will generate a warning on Omega. If your code produces ANYwarnings/errors when compiled on Omega, you will receive a 0 on the assignment. Take the time to learn how to use Omegaand compile this assignment on Omega before submitting.You will create 7 files and submit them as one zip file – Code6_xxxxxxxxxx.zipmakefileCode6_xxxxxxxxxx.cGameLib.cGameLib.hFileLib.cFileLib.hPhraseBank.txtPlease note you that will NOT be able to put your name/id at the top of PhraseBank.txt. Also, remember to use UNIX EOLconversions. Either change your file to UNIX in your editor before transferring or use these UNIX commands to change the fileon Omega.cp PhraseBank.txt PB.txtcat PB.txt | tr ‘r ‘ ‘n ‘ | tr -s ‘n ‘ > PhraseBank.txtCreate your own PhraseBank.txt file.I have provided an example PhraseBank.txt file and you will need to create your own. You must have at least 5 lines inyour file. They do not need to be songs like the example (but they can be). You just need to use something that has similarinformation. For example, you could use a movie title, the lead actor, the year it was released and the production company.You need to provide at least 4 fields where one of them is the field to be guessed and other three are used in the menu. Eachfield in the file should be separated by the pipe symbol (|). Please be professional and keep your choices PG. You will submityour own version of the file but the name of the file must be PhraseBank.txt. Your program will be tested with your fileand with a different variation of your file. Do not hardcode anything in your program using values based on the lines in the file.GameLib.cStartGame()Parameters Empty array for chosen phrase, File Handle, Array of PhrasesReturn Value The index of the chosen phrase from the array of phrasesReplace the include for PhraseBank.txt with a call to ReadFileIntoArray(). If ReadFileIntoArray() returns0, then print “All of the games have been played – please reload file” and use exit(0) to stop theprogram. Change the welcome to the game message to match what type of information you are using for your game. Changeyour menu to display the information as shown the sample output. Function DashIt() no longer needs to be called insideStartGame() since the menu no longer uses the actual phrases to be guessed. ReadFileIntoArray() will return thenumber of records it read and that value should be used to display the menu. StartGame() will now return the index fromthe array of the chosen entry.The rest of the functions in GameLib.c should have no changes.GameLib.hAdd the typedef struct to hold the data from a line in your file. With my song game, I created a structure with a charpointer for artist, a char pointer for song title, a char pointer for album name and a regular char array to hold the releasedate. Your structure must contain at least 3 char pointers and at least one member that has a known size that does notchange. In my example, release year, will always be of size 5 (4 for the year and 1 for the NULL); therefore, no need to usemalloc() on it since it will not vary. Your variable names must sufficiently describe their use.FileLib.cThis file contains 3 new functionsOpenFileA function to open a file. Should take 3 parameters – argc, argv and mode. This function should open the filenamefound in argv[1]. Make sure there are enough command line parameters before you use argv[1]. If thecommand line parameter is missing, prompt the user to enter a name. Your program should work with either acommand line parameter file name or by entering the filename at a prompt. Try to open the file using the passed inmode. If the open fails, prompt again for a filename. Keep prompting for a filename until able to open the file. Whilecondition should be properly formed – no arbitrary values or using break/continue/return/exit. Function should returnthe file handle once the file has successfully opened.ReadFileIntoArrayA function to read the file and store the contents in the array of structures. The array of structures and the file handle(which was returned by the function to open a file) should be passed into this function. It will return the number ofrecords that were read from the file. Use fgets() to read through the file. If the file line starts with a blank, thenuse continue to not process the line. Replace the n at the end of the line with a NULL. Ensure that you do notread more records from the file than the array can hold (MAX_ENTRIES). Use strtok() to find each field in eachfile line. Use malloc() to allocate the space and strcpy() to copy the token into the malloc’d memory.WriteFileA function to write out a new version of the file. Pass in the array, the index that was returned by StartGame() andthe file handle. After correctly guessing and winning, the entry that was used should be removed from the file so thatthe next game does not include that entry the player has already guessed. Since the file was opened using a mode ofr+, the file can be written to after it has been read. Write the contents of the array to the file and skip the winningentry. There will be an extra line at the end of the file that you will need to blank out. Use a combination of fseek()and ftell() to figure out how many blanks to write to the file to blank out the extra line. Be sure to free yourdynamically allocated memory and close the file.FileLib.hThis file contains the prototypes for the 3 functions in FileLib.c. Must contain an include guard.main()Create an array of size MAX_ENTRIES of your typedefed structure.Call your new function to open a file. The return value of that function should be a file handle (FILE *).Call function StartGame(). You are passing the empty Phrase and the file handle and the array. It should return theindex of the chosen entry from the array. The rest of main() should continue to work like it did in Coding Assignment 5.If the player wins the game, call your new function to write out the new version of the file.BONUS – 10%Add advanced command line parameter handling so that your program can be runCode6_xxxxxxxxxx.e FILENAME=PhraseBank.txtSample OutputSample Filemore PhraseBank.txtThe Bangles|Walk Like an Egyptian|1986|Different LightGregory Abbott|Shake You Down|1986|Shake You DownWhitney Houston|I Wanna Dance with Somebody|1987|WhitneyStarship|Nothing’s Going to Stop Us Now|1987|No ProtectionB*Witched|C’est La Vie|1998|Fresh Hits 8Bon Jovi|Livin’ on a Prayer|1986|Slippery When WetBeastie Boys|(You Gotta) Fight for Your Right (To Party)|1986|Licensed to IllPrince|Sign o’ the Times|1987|Sign o’ the TimesJanet Jackson|Let’s Wait Awhile|1986|ControlCrowded House|Don’t Dream It’s Over|1986|Crowded HouseWith command line parameter file nameCode6_1000074079.e PhraseBank.txtWelcome to 3 STRIKES – YOU’RE OUT – the CSE versionPlease pick a song from the following menu1. The Bangles’s song that was released in 1986 on album Different Light2. Gregory Abbott’s song that was released in 1986 on album Shake You Down3. Whitney Houston’s song that was released in 1987 on album Whitney4. Starship’s song that was released in 1987 on album No Protection5. B*Witched’s song that was released in 1998 on album Fresh Hits 86. Bon Jovi’s song that was released in 1986 on album Slippery When Wet7. Beastie Boys’s song that was released in 1986 on album Licensed to Ill8. Prince’s song that was released in 1987 on album Sign o’ the Times9. Janet Jackson’s song that was released in 1986 on album Control10. Crowded House’s song that was released in 1986 on album Crowded HouseEnter choice :Without command line parameter file nameCode6_1000074079.eMust be run with an input file name.Enter a file name at the prompt PhraseBankCould not open a file named PhraseBank.Enter a file name at the prompt PraseBank.txtCould not open a file named PraseBank.txt.Enter a file name at the prompt PhraseBank.txtWelcome to 3 STRIKES – YOU’RE OUT – the CSE versionPlease pick a song from the following menu1. The Bangles’s song that was released in 1986 on album Different Light2. Gregory Abbott’s song that was released in 1986 on album Shake You Down3. Whitney Houston’s song that was released in 1987 on album Whitney4. Starship’s song that was released in 1987 on album No Protection5. B*Witched’s song that was released in 1998 on album Fresh Hits 86. Bon Jovi’s song that was released in 1986 on album Slippery When Wet7. Beastie Boys’s song that was released in 1986 on album Licensed to Ill8. Prince’s song that was released in 1987 on album Sign o’ the Times9. Janet Jackson’s song that was released in 1986 on album Control10. Crowded House’s song that was released in 1986 on album Crowded HouseEnter choice :Entering an invalid menu choiceWelcome to 3 STRIKES – YOU’RE OUT – the CSE versionPlease pick a song from the following menu1. The Bangles’s song that was released in 1986 on album Different Light2. Gregory Abbott’s song that was released in 1986 on album Shake You Down3. Whitney Houston’s song that was released in 1987 on album Whitney4. Starship’s song that was released in 1987 on album No Protection5. B*Witched’s song that was released in 1998 on album Fresh Hits 86. Bon Jovi’s song that was released in 1986 on album Slippery When Wet7. Beastie Boys’s song that was released in 1986 on album Licensed to Ill8. Prince’s song that was released in 1987 on album Sign o’ the Times9. Janet Jackson’s song that was released in 1986 on album Control10. Crowded House’s song that was released in 1986 on album Crowded HouseEnter choice : 0You entered an invalid choice.Please reenter -1You entered an invalid choice.Please reenter 11You entered an invalid choice.Please reenter 3Here’s the phrase you need to guess– —– —– —- ——–Guess a letter :HINTSRemember that fseek() can be used to move the file pointer to different positions.You can use ftell() to get the current position, use fseek() to move to the end of the file and then use ftell() againto get the value of the file pointer. If you subtract those two ftell() values, then you will know how many bytes arebetween them.You can then move the file pointer back to where it started using fseek() and write out the needed number ofspaces/blanks.Your program will be tested using the file you create. My sample file is just a sample – your program/structure will need itsown file.The GTA will alter your file during tests to add more lines and to change the length of various fields. This will test that you arenot overflowing your array and that you are not hardcoding anything about the malloc’d fields.When you create your array of structures, you should be setting it to NULL using = {}. You will need to rely on unfilledelements being NULL when you are writing out the file. You are not allowed to pass in the number of elements to write or useany sort of global variable. You just need to write out the non NULL cells of your array.When you call your function to open the file, the 3rd parameter is the mode. Pass the mode as “r+” in the call to the function.FH = OpenFile(argc, argv, “r+”);where FH is a variable of type FILE *We could have gotten it from the user on the command line or through a prompt, but our program relies on that value beingr+ so that it can read the file and then overwrite it at the end. So, our program is forcing/setting the mode instead.