I have a C code, which prompts users for list of directory name, it just uses plain scanf() to receive the input and proceeds. Now I would like to provide autocomplete for directory names (like bash does). Say user enter /home/a and press TAB – it displays list of available user directories that begins with ‘a’.how to achieve this?
Share
scanfis not suitable for any kind of auto-complete or even interactive editing beyond the basic level (essentially just backspace) that the kernel cooked-mode terminal driver provides. If you want to do fancier interactive input, you need to change the terminal modes so you get each key event and process them yourself, or you can use a library likereadlinethat does this for you.