Original Post
Hi, I have a FSM type of code in which I am trying to avoid the second call. For example I am calling (*CallAI)(Idle). What I really want to do is just do CallAI = &Idle and then somehow force the function to run. Is this possible ? For eg:- If you see in the main function I have the line CallAI = &Idle. I want to have only a line like this and somehow force the Idle function to execute. Is this possible. Thanks
[Source]
void AIFsm(char ch)
{
switch(ch)
{
case 'i' :
CallAI = &Idle
(*CallAI)(Idle);
break;
case 'w' :
CallAI = &Wander
(*CallAI)(Wander);
break;
case 'f' :
CallAI = &Flee
(*CallAI)(Flee);
break;
default :
break;
}
}
int main()
{
char ch;
CallAI = &Idle /* Want to do something like this and make sure Idle
function gets called */
while(1)
{
ch = fgetc(stdin);
if(ch == 'q')
{
break;
}
else
{
AIFsm(ch);
}
}
return 0;
}
[/Source]