Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Exercise: Selector with list of items from a file

  • Write a program that will get a file on the command line.
  • It will display a menu allowing the user to select item by selecting the number next to it.
  • e.g. the file looks like this:
blue
yellow
green
black

The menu should look like this:

1) blue
2) yellow
3) green
4) black
  • The user then can select a number (e.g. 3) and the program prints "green".
  • Make sure the program handles well if the input is invalid.