On Sat, 26 Apr 2008 20:14:37 -0700 (PDT), Sunil <sr*******@gmail.com>
wrote in comp.lang.c:
I am trying to see as to what kind of input such as below can produce
a output. If you see for input 7, the output is " and for 8 is v. I am
trying to determine what can generate an output in this format using C
Thanks
Please enter a key to continue : 7
Input 7 Output "
Please enter a key to continue : 8
Input 8 Output v
Please enter a key to continue : 9
Input 9 Output $
Please enter a key to continue : !
Input ! Output @
Please enter a key to continue : a
Input a Output #
Please enter a key to continue : b
Input b Output @
Please enter a key to continue : c
Input c Output E
Please enter a key to continue : d
Input d Output @
Please enter a key to continue : e
Input e Output %
Please enter a key to continue : f
Input f Output #
Please enter a key to continue : g
Input g Output G
Please enter a key to continue : h
Input h Output #
Your question does not make it very clear what it is that you are
trying to do.
One easy way to have an arbitrary one-to-one map of one set of
characters to another is to have an array of structures like this:
struct char_map { int in, int out };
struct char_map table [] =
{
{ '7', '"' },
{ '8', 'v' },
/* and so on, for however many you need */
};
Then when you receive an input character, you search the first member
of every structure in the array to see if there is a match. If there
is, you output the second member of the structure.
Another possibility is to use a pair of strings:
const char inputs [] = "789!abcdefgh";
const char output [] = "\"v$@#@E@%#G#";
You can search the input string for the input character with strchr(),
and use its distance from the start of the string (if it is found) to
compute the index into the replacement string.
In either approach, you have to decide what to do if the input does
not match one of your defines substitution patterns.
--
Jack Klein
Home:
http://JK-Technology.Com
FAQs for
comp.lang.c
http://c-faq.com/
comp.lang.c++
http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html