hey guys im trying to make a table look up for a collection of functions so i have chosen to use a table look up with a function pointer run by a 2 character string..
Code:
const struct Node{
char cmd[3]; // type this letter
void (*fnctPt)(void);}; // to execute this command
typedef const struct Node NodeType;
typedef NodeType * NodePtr;
NodeType TL[]={ // linear linked list
{ "FF", &Forward},
{ "RR", &Reverse},
{ "TL", &Turn_L},
{ "TR", &Turn_R},
{ "RL", &Rotate_L},
{ "RR", &Rotate_R},
{ "HH", &Cmd_OPT}};
void Interpreter(char *string){
NodePtr pt;
const int table_length = sizeof(TL)/sizeof(*TL);
int row;
for(row=0; row < table_length; row++){
pt = &TL[row];
if(strcmp(string, &pt->cmd)){
pt->fnctPt();
}
else{
SCI_OutString("Error");
}
}
}
if any of youhave time to try it here is the current project
https://www.dropbox.com/s/s9lcvzlmax3e8it/proj.zip