Storing key-value pairs in plain C

c, dictionary

Solution

You are looking for an associative container. There is no "direct" way in C, since the standard library does not provide any data structure. You can try to look for a third party library that provides the functionality, or roll your own solution.

Problem

I'm trying to find a way of storing "key, value" pairs in C in an efficient manner for quick data retrieval. I've been looking online and there doesn't seem to be a quick and easy way of storing them such as in Java. I'll need to be able to access and update the value frequently and also being able to add new keys in and sort them into order. I've read about using `qsort()` and `bsearch()` to accomplish those, but I'm not sure what data structure to use to store it all.

Original source

Related problems