I have a look up table as follows:
// A structure to hold all the commands and function pointers
typedef struct
{
char functionName[256];// The function name is used to refer to the function pointer
int (_stdcall *myfunction)(char *, char *); // This defines the function pointer
} LOOKUP_TABLE;
// This lookup table holds all TSL1 commands and their related functions
static const LOOKUP_TABLE lookUpTable[] =
{
{"ReadMemory8", pTSL1_Commands->DIAG_ReadMem8},
{"ReadMemory16", pTSL1_Commands->DIAG_ReadMem16},
{"ReadMemory32", pTSL1_Commands->DIAG_ReadMem32},
{"ReadMemory64", pTSL1_Commands->DIAG_ReadMem64},
{NULL, NULL}
};
I have a variable, sCmdInt[0] which holds a string to be compared to the elements in the lookup table.
Can anyone help with how to loop around the lookup table to find a match for the function? I have tried the following:
int n = sizeof(lookUpTable)/sizeof(*lookUpTable);
for (int i = 0; i < n; i++)
{
if(sCmdInt[0] == lookUpTable->functionName[i])
{
(*(lookUpTable[i].myfunction(sCmdInt[0], returnData)));
}
}
My function, when called, also takes sCmdInt[0] and returnData as parameters.
Any help appreciated.