
Newbie needs help with something simple!
Groovy hepcat Rick49 was jivin' on Tue, 20 Oct 1998 01:52:34 GMT in
comp.lang.c.
Re: Newbie needs help with something simple!'s a cool scene! Dig it!
Quote:
> if (input =='a') printf("apple \n");
> if (input =='b') printf("book \n");
A much easier way than this would use a switch here instead of
multiple if(...) statements.
But a lokup table would be cleaner. For example (assuming a system
in which the letters a to z are contiguous and in order in the
prevailing character set, eg. ASCII):
#include <stdio.h>
#include <ctype.h>
int main(void)
{
char *word[] = {"Apple",
"Book",
... };
int c;
printf("Enter a letter: ");
fflush(stdout);
c = tolower(getchar()) - 'a';
printf("%s\n", word[c]);
return 0;
Quote:
}
--
----- Dig the EVEN NEWER, MORE IMPROVED news sig!! -----
-------------- Shaggy was here! ---------------
http://aardvark.apana.org.au/~phaywood/
============= Ain't I'm a dawg!! ==============