I am writing a shell that needs a command interpreter. The current pattern I am using is as follows:
if(strcmp(command, "my_cmd_keyword1") == 0) {
...
}
else if(strcmp(command, "my_cmd_keyword2") == 0) {
..
}
...
However, the number of predefined command keywords might be very huge. The if-else branching turns out to be inefficient since it has to compare with every keyword (in the worst case). Is there any more efficient way to handle this? I am using C/C++ languages for my applications.