Path: utzoo!utgpu!water!watmath!clyde!att!pacbell!ames!ucsd!sdcc6!loral!jlh From: jlh@loral.UUCP (The Mad Merkin Hunter) Newsgroups: comp.lang.c Subject: Table lookups Message-ID: <1802@loral.UUCP> Date: 25 Jun 88 18:44:58 GMT Organization: Under the table Lines: 24 Lets say I have a value that can range from 0-15 and I want to print an ascii string based on that value. Normally I create an array of strings and index into it. K&R does this with the names of the months when they talk about arrays of pointers. Now lets say that instead of index values from 0-15 I have bit positions, i.e., the values are 0x1, 0x2, 0x4, ..., 0x80. I'd like to do a table lookup on these values also, as opposed to building a switch statement. The only methods I can come up with take a lot longer and are much less clear than the switch statement (for example, logarithms). Anyone got any ideas? To quell the flames rising in your breasts, let me say that this isn't one of the major questions of the universe. It's just that for the kind of programming I do this comes up quite a bit, and my sense of order gets it's nose tweaked everytime I type in the 'case 0x?? :doit;break' sequence. Jim -- Jim Harkins Loral Instrumentation, San Diego {ucbvax, ittvax!dcdwest, akgua, decvax, ihnp4}!ucsd!sdcc6!loral!jlh