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