Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in c Create a that contains the following fields: - (a char array of size 32) - (a char array of size 16) - hp

in c

image text in transcribedimage text in transcribedimage text in transcribed

Create a that contains the following fields: - (a char array of size 32) - (a char array of size 16) - hp (an int) - (an int) This struct should be defined in a header file called monster. h. Make sure you include a header guard. In monster. c, implement a function named create_monster that prompts the user to enter the values for each field of the struct monster. The function should return a struct monster object. Additionally, create a function called print_monster that takes a as a parameter and prints the data in the following format: Name: name Type: type HP: hp Level: level Include the declarations for these functions in monster. h. Create a third file named test_add_monster. c that includes and tests your and function. Now that the monster is defined and we can add new entries in memory, we need to be able to save the data to a file. Create a function named that takes a and a FILE pointer as parameters. The function should write the as binary data. You can assume that the given pointer is already open for writing. Define this function in and include the declaration in Create a third file named that includes and tests your function by creating a monster with and saving it to a file. Make sure to open the file in append mode so that new entries will save to the end of the file. The next step is to load the data from the file into memory. Create a function named that takes a FILE pointer as a parameter. The function should read the next line from the file and return a object. You can assume that the given FILE pointer is already open for reading. Since this data is stored in a binary file, you will need to use the fread function to load the data. Since the data was written in the same order that it was read, you can use the same fread calls to load the data into a monster array. You can assume that the file contains less than 128 monster objects. We will also need a way to display the data after loading. Create a function named print_monsters that takes an array of struct monster objects and the number of elements in the array as parameters. It should print a table of the data in the following format: Namename1name2Typetype1type2HPhp1hp2Levellevel1level2 Create a file named that includes monster.h and tests your and functions by loading the data from the file and printing it to the screen

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions