Associative array or database for AI?

Hi, being a proficient googler, this is my first time using a forum EVER, so please bear with me.
I've been looking up how to create a database file that works like a dictionary, having a string with corresponding values stored in different entries on the same line. The problem is, while there is a lot of help out there on previous forums, the context of the questions are very different to what my database(s) are needed for.
I've put this in the beginner's forums because I think what I'm working on is (ambitious) beginner code but with advanced logic. The most advanced stuff I've done is defining strings as 'char[]' instead of 'string'.
Some contextual notes:
I've created a zork-style text based adventure game engine from scratch using string comparison functions and a LOT of arrays/improvised dictionaries. The memory-hungriness has been manageable from this point, but I am planning on implementing an AI feature, so you can interact dynamically with NPCs in the game. e.g. if you insult the NPC, it insults you back. If you go too far, it tries to kill you.
As a result, using arrays to contain literally the entire english dictionary and corresponding machine-understandable instructions will be, well, silly.
The handy thing though, is that because this is in-game, I only need to worry about adjectives, prepositions, verbs, and pronouns. I can leave out a massive amount of nouns out, because if they don't exist in the game, they don't need to be taught to the AI!

To make my question a bit clearer:
I need to create a SIMPLE database file or otherwise to store a list of english words and corresponding machine-understandable entries.
e.g. (adjective dictionary)

happy, EH1,
ecstatic, EH3,
sad, ES1,

I also will need help finding out how to read the file quickly, and get the corresponding values with minimal stress!

I've probably given more information than needed, but too much information is better than too little, I guess.

ANY help would be appreciated, and I welcome any other suggestions you may have for me to improve my game!

By the way if other forums are anything to go by, you might appreciate that I have no intention of making money off any of this, open source and all that, this is just a side project of mine with a chance of getting into a science fair...
Last edited on
Check out the STL <map>. It uses an self balancing AVL tree so it is very efficient.

I am a bit confused by this:

The most advanced stuff I've done is defining strings as 'char[]' instead of 'string'.

A string is a far better option over a char array, unless you are super worried about overhead. Unless you have a million or so items I wouldn't worry about it.

Good Luck !!!!!
Thanks! I'm looking into it now.
Is this the best way to add the entries:
// Define map:
map<string, string> Adjectives;

// Add elements:
Adjectives["happy"] = "EH1";
Adjectives["ecstatic"] = "EH3";
Adjectives["sad"] = "ES1";

or is there a way of lumping it all together like you can in a multi-dimensional array? e.g.
// Define array -and- add elements:
char[2][] Adjectives = {
"happy", "EH1",
"ecstatic", "EH3",
"sad", "ES1",
// Tell loops when array ends:
"\0", "\0",

(This example is how I added info previously)
Topic archived. No new replies allowed.