On Thu, May 29, 2008 at 11:26:34PM -0700,
wrote:
> I wrote ,as homework, a program that displays words after key pressed.
> So, if letter 'A' is pressed, the word 'dog' appears; if letter 'B' is
> pressed 'cat' appears; if letter 'a' is pressed 'apple' appears; and
> so on...
> I wrote this program with a lot of switch case, so i want to obtain a
> smaller program (if possible)...can you help me?
What you would like to do is to map integers to strings.
How about an array?
const char *my_lovely_words[UCHAR_MAX];
Please stop reading here, try to write the program, and then you may continue.
my_lovely_words['a']="apple";
....
But I do not see how that would save you much keystrokes.
In C99 you can have named initialisers
const char *my_lovely_words[]={
['A']="dog",
['a']="apple",
};
Szabolcs