Originally Posted by
Nick Colby
I want to write a simple application which will preform different action based on different input. For example I would want say 5 options, 5 different keys to choose from, say 1 - 5. How would I give different functions to different keys? So if someone choose "1" that it would preform actions from "1" and not say "2".
It sounds like you want a multi-way decision. In C the normal way is either a switch statement or an if ... else if ... else if ... else sequence. One simple example: suppose you have read the code you described as a digit '1'...'3' and you have already defined three functions action_one, action_two, action_three. Then you could run something like this in a loop:
Code:
switch(code) {
case '1':
action_one();
break;
case '2':
action_two();
break;
case '3':
action_three();
break;
default:
printf("Unknown code\n");
}