Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

5. Create a program that reads and writes creature data from and to a file using fread() and fwrite(). The creature data should be represented

image text in transcribedimage text in transcribed

image text in transcribed

5. Create a program that reads and writes creature data from and to a file using fread() and fwrite(). The creature data should be represented as a struct with the following data members: Name . CR AC HP Your program should include a menu that allows the user to list creature data or add a new creature. It should keep the user inside the program until they choose an option to exit. The struct should be defined using typedef. The data file should be passed as a command line argument. . If the file cannot be opened for any reason, warn the user. If the file does not exist, create it. The program should check for invalid input in the menu. You can assume valid data will be entered for the creatures. Your output should match the output shown in the example below. Take care that the divider line is the same length as the name and that the entries have an empty line between them. After adding a creature, it should be written (append) to the file. Save your code as creature_db.c. Example Run Adding Creatures 1. List Creatures 2. Add Creature 3. Exit > 2 Enter Name: Adult Blue Dragon Enter Challenge Rating: 16 Enter Armor Class: 19 Enter Hit Points: 225 Creature added! Example Run - List Creatures 1. List Creatures 2. Add Creature 3. Exit > 1 Beholder CR: 13 AC: 18 HP: 180 Adult Blue Dragon CR: 16 AC: 19 HP: 225 5. Create a program that reads and writes creature data from and to a file using fread() and fwrite(). The creature data should be represented as a struct with the following data members: Name . CR AC HP Your program should include a menu that allows the user to list creature data or add a new creature. It should keep the user inside the program until they choose an option to exit. The struct should be defined using typedef. The data file should be passed as a command line argument. . If the file cannot be opened for any reason, warn the user. If the file does not exist, create it. The program should check for invalid input in the menu. You can assume valid data will be entered for the creatures. Your output should match the output shown in the example below. Take care that the divider line is the same length as the name and that the entries have an empty line between them. After adding a creature, it should be written (append) to the file. Save your code as creature_db.c. Example Run Adding Creatures 1. List Creatures 2. Add Creature 3. Exit > 2 Enter Name: Adult Blue Dragon Enter Challenge Rating: 16 Enter Armor Class: 19 Enter Hit Points: 225 Creature added! Example Run - List Creatures 1. List Creatures 2. Add Creature 3. Exit > 1 Beholder CR: 13 AC: 18 HP: 180 Adult Blue Dragon CR: 16 AC: 19 HP: 225

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

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

5. Who should facilitate the focus group?

Answered: 1 week ago