Answered step by step
Verified Expert Solution
Question
1 Approved Answer
in c in c Create a monster struct that contains the following fields: name (a char array of size 32) - type (a char array
in c
in c
Create a monster struct that contains the following fields: name (a char array of size 32) - type (a char array of size 16) - hp (an int) - tevel) (an int) This struct should be defined in a header file called 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 retutin a struct monster object. Additionally, create a function called print_monster that takes a struct monster as a parameter and prints the data in the following format: Nane: name Type: type HP: hp Level: level Include the declarations for these functions in monster. h. Create a third file named that includes monster. h and tests your and print_monster function. Now that the monster is defined and we can add new entries in memory, we need to be able to save the data toa file. Create a function named save_monster that takes a struct monster and a FILE pointer as parameters. The function should write the conster as binary date. You can assume that the given (FILE pointer is already open for writing. Deline this function in conster. c and include the declaration in Create a third file named test_save_monster.c) that includes conster.h and tests your save monster funetion by creating a conster with create_monster 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 foad_monster that takes a FILE pointer as a parameter. The function should read the next line from the file and return a struct monster 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 dats was written in the same order that it was read, you can use the same (fread) calls to load the data into a struct 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_-ionsters 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: \begin{tabular}{lll} Nane & Type & HP Level \\ \hline name1 & type1 & hp1 level1 \\ nane2 & typez & hp2 level2 \\ ... & & \end{tabular} Create a file named test_Load_monsters.c that includes monster.h and tests your Load_monster and print_consters functions by loading the data from the file and printing it to the screen. The included code examples use standard array indexing notation. Convert the indexing notation to an equivalent program using pointer arithmetic. Array initializations do not need to be converted since they define the anray memory. For array_utits.c) and array_tests. c, you can verify that it is working by compiling both of the fliles together. For example, you can complle with the following command: gcc0 array_tests array_utils.c array_tests.c C amaytests.c x Y_utils.c > *inctude "array_utits.h" int insert(int vatue, int index, int arrti, int size) f if (index se MAX SIZEE) \& printf("WAENTNo] Invatid index to inserto (n) s return stzeb II Append if (index = size) t arr [size] = vatues return size +1i if (index = index ){ arr[1+1]=arr[1]; arr[ index ]= value; return size +1; int renove val(int index, int arr[], int size) \{ for ( int 1= index; 1Step 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