I need your help in writing a efficient program.
I have approx 50 functions say call_1(), call_2() … call_50(). I need to call them based on the index read from a data packet, i.e if the field in data is 25 in need to call call_25(), if 10 then call_10().
I have written this in if else condition like
if (index == 5)
call_5()
elseif (index == 6)
..so on ..
But I think this is not the efficient way of writing. Any other ideas of implementing this scenario?
Can function pointers help here?
Appreciate your help. thanks.
Yes, use a lookup table of function pointers: