#include #include #include void help( void ); void quit( void ); struct Command { char *command; void ( *func )( void ); }; struct Command theCommands[ ] = { "exit", quit, "help", help, "quit", quit, NULL, NULL /* Place Last; No Match */ }; void doCommand( const char *comm ) { struct Command *ptr; for( ptr = theCommands; ptr->command != NULL; ptr++ ) if( strcmp( comm, ptr->command ) == 0 ) { ( *ptr->func )( ); return; } printf( "Error: unrecognized command\n" ); } void help( ) { printf( "Here's my help!\n" ); } void quit( ) { exit( 0 ); } int main( ) { char command[ 1024 ]; printf( "> " ); while( scanf( "%s", command ) == 1 ) { doCommand( command ); printf( "> " ); } return 0; }