C Example: Command Table: function-pointer dispatch for text commands
Builds a command table of name plus function pointer, registers echo, upper, count and help, splits each input line at the first space into command and argument, looks up the table and calls the matching function; misses print unknown. Shows table-driven dispatch replacing a long if/else chain.
🖥 Run OnlineGCC 10.2 · C11 standard · click ▶ to run · Copy code
🖨 Reference OutputMatches the online run in a standard C11 environment
echo: hello world upper:C POINTERS count: 3 words, 13 chars commands: echo, upper, count, help unknown command: unknown
🧩 Keep Learning