From: <e....@wo...> - 2002-12-10 17:24:55
|
Hi list, I have some problems with the code below. The idea is to have a common function, interpreting a given set of char commands, working on a structure, providing it with the command-string, the number of commands and an array with pointers to the functions to be called. :) Ok, more slow... I have a structure defined like this struct menu_struct { char *commands; // string of chars byte count_of; // ... them void (*(*what_to_do)[])(); // guess what it should be :) }; just as a typedef in a global headerfile. In the sourcefile I have struct menu_struct *a1; to have a pointer to such a structure. Initialized such a structure like this code struct menu_struct Root={ "123456", 6, Level0 }; where Level0 is defined like this code void (*(Level0)[])()={ funktion1, funktion2, funktion3, funktion4, funktion5, funktion6 }; the funktions are defined somewhere in the same sourcefile and prototyped properly. Pointer a1 is initialized like this void init_command(void){ a1 = &Root; } The command interpreter goes like this void command(byte cmd){ byte i=a1->count_of; do{ if(a1->commands[--i]==cmd){ (*(a1->what_to_do)[i])(); // Here comes debugging stuff Disp_dec(cmd); Disp_char(a1->commands[i]); break; } }while(i); } My Problem: It always finds the correct command in the command-string after the right number of loops AND it calls a function out of the array BUT it calls ONLY the first function "function1", even if I give him a '6' or a '1' or whatelse. Please give me a breakthrough or at least an idea where am I could be blocked @:? -- Kind Regards Eckhard Doll e....@wo... |