From ddf08bfef0eaa55ae7aeca2873bb75f9d4ada484 Mon Sep 17 00:00:00 2001 From: Kai Kehres Date: Sat, 28 Jan 2023 21:00:41 +0100 Subject: [PATCH] prod: created function getItemInInventory --- src/c/character.c | 16 +++++++++++++++- src/c/character.h | 2 ++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/c/character.c b/src/c/character.c index 141be76..148ed4f 100644 --- a/src/c/character.c +++ b/src/c/character.c @@ -259,9 +259,23 @@ void putItemInInventory (Character *character, Item *item,int inventorySlot) { printf("Inventory slot is out of range (0-9)\n"); } else if (inventorySlot < 0) { printf("Inventory slot is out of range (0-9)\n"); - } else if (character->inventory[inventorySlot] != NULL) { + } else if (character->inventory[inventorySlot] == NULL) { printf("Inventory slot is already occupied\n"); } else { character->inventory[inventorySlot] = item; } +} +Item * getItemInInventory (Character *character, int inventorySlot) { + if(inventorySlot > 9) { + printf("Inventory slot is out of range (0-9)\n"); + return NULL; + } else if (inventorySlot < 0) { + printf("Inventory slot is out of range (0-9)\n"); + return NULL; + } else if (character->inventory[inventorySlot] == NULL) { + printf("Inventory slot is empty\n"); + return NULL; + } else { + return character->inventory[inventorySlot]; + } } \ No newline at end of file diff --git a/src/c/character.h b/src/c/character.h index c47f8f6..d7fb70f 100644 --- a/src/c/character.h +++ b/src/c/character.h @@ -124,4 +124,6 @@ char* getItemName (Item *item); void putItemInInventory (Character *character, Item *item, int inventorySlot); void initializeInventory (Character *character); + +Item * getItemInInventory (Character *character, int inventorySlot); #endif \ No newline at end of file