I always do that, it seems elegant and light to me.
You simply define an array, as usual, without a fixed index.
All you have to do is add one 0 to the end.
You can then make the shortest TEST possible and skip it with or over.
Here's an example, it displays a list of options and an installation help item (in this case, the help array should be at least until it is selected.
const char *options[]={ "CAL_MAG_MIN", "CAL_MAG_MAX", 0 }; const char *help[]={ "<X,Y,Z>", "<X,Y,Z>", 0 }; int pos; for (pos=0;options[pos];pos++) { printf("\t %s %s\n",options[pos],help[pos]); }
John
source share