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 23:04

>>12
>May I direct you to the tittle, 'Help in C'.
C is what you make it.

>It is not easy to to store random functions in a config file.
A look up table can store an arbitrary function defined on a finite domain. In the op's case, it's a function defined on a domain consisting of 100 strings. The keys are easy to represent in the config file, but the values might be another story. If they are code pointers or something, it might all need to be hard coded anyways.

>On the other hand, and array of structs with a string and function pointer, is simple as dirt.
So is bubble sort. This isn't as extreme, but it is a good example of when C encourages implementations that don't scale optimally.

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