I am stuck on this problem and I am not sure what the solution is. In...

90.2K

Verified Solution

Question

Programming

I am stuck on this problem and I am not sure what the solutionis. In C

Write item.h and item.c.

In item.h, typedef a struct (of type t_item) which contains thefollowing information: t_item: char name[MAX_ITEM_NAME_STRING];char description[MAX_ITEM_DESCRIPTION_STRING];

Make sure that MAX_ITEM_NAME_STRING andMAX_ITEM_DESCRIPTION_STRING are defined with suitable sizes in youritem.h.

Typical values are, 25 and 80, respectively. Add the followinginterface definition to item.h: int item_load_items(t_item items[],int max_items, char *filename);

Returns the number of objects loaded from the filename (or -1 ifunable to open the file and load the data). Fills the t_item arrayitems with the contents of a file entitled \"items.txt\" intitem_find_item(t_item items[], int max_items, char *item_name);

Returns the array index of the item with the item_name or -1 ifnot present. Make sure that you have a header guard around yourdeclarations in item.h Header guards:(https://www.learncpp.com/cpp-tutorial/header-guards/) Implementthe item_load_items and item_find_item functions in the item.cfile. Use the provided main program to test your item.h and item.cfiles. Test it with the provided file, items.txt.

Here is my main.

**********************************************************
#include

#include \"item.h\"

#define MAX_ITEMS 10

int main()
{
int place;
int num_items = 0;
t_item items[MAX_ITEMS];
  
if( (num_items = item_load_items(items, MAX_ITEMS, \"items.txt\"))> 0 )
{
for(int i=0; i   {
   printf(\"%d\t\\"%s\\"\t\\"%s\\"\n\", i, items[i].name,items[i].description);
   }


for(int i=0; i   {
   if( (place = item_find_item(items, num_items,items[i].name)) > -1)
   {
   printf(\"Item %s is found at location %d\n\",items[i].name, place);
   }
   else
   {
   printf(\"Can't find %s\n\", items[i].name);
   }
   }
}
else
{
printf(\"ERROR: Unable to load items\n\");
}
}

****************************************************************

This is text file

\"kinfe\",\"a large knife\"
\"spike\",\"a large spike made of metal\"
\"sword\",\"buster sword\"
\"bow\",\"reflexive bow\"

Answer & Explanation Solved by verified expert
3.8 Ratings (709 Votes)
Codeitemhifndef ITEMHdefine ITEMHdefine MAXITEMNAMESTRING 25define MAXITEMDESCRIPTIONSTRING 80typedef    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students