Practice ยท 1 of 4
The Command Table
Implement a table-driven calculator:
``c
/* runs the named binary command: "add", "sub", "mul".
Returns the result, or INT_MAX for an unknown name. */
int calc(const char *name, int a, int b);
/* returns the number of registered commands */
size_t calc_count(void);
/* returns 1 if name is registered, 0 otherwise */
int calc_has(const char *name);
``
The dispatch table must be data (an array the functions walk) โ no strcmp
if-chains inside calc.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Dispatch & Context Gym