Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Help in C

Name: Anonymous 2012-04-09 0:47

I need to execute certain commands depending on what the value of a string is. Instead of making a lot of if statements to check the string against all possible cases I thought I would hah the strings and hash the possible values for the string for which i want to do something then handle it with a switch statement. The number of different strings I'll be comparing it to is less than 100 so i dont have to worry about collisions. Is this a good idea? Do you have other ideas?

Name: Anonymous 2012-04-09 16:26

>>11
>which is dependent on what language features you have. Some actually have the string switches that OP wants built in.

May I direct you to the tittle, 'Help in C'.

>A completely flexible solution would be to just use a mutable hash table, load it when the program starts via a config file, and then use it for look ups.

By having a config file you've introduced a lot more complexity.  And while it's easy to load strings from a config file in C.  It is not easy to to store random functions in a config file.

On the other hand, and array of structs with a string and function pointer, is simple as dirt.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List