Get input using tab instead of Enter key in C-Linux


I am developing linux-like shell in C. The first and basic requirement is to get infinite input (probably commands like rm kill etc. , which will execute) from user & upon Tab key, list of possible commands must be output to the screen.


My question is that how to get the input upon Tab Key press instead of Enter key?

A quick example will be very helpful, since I'm a college student learning C as part of OS course.

1 answer

  • answered 2018-05-16 05:31 dmitrygrach

    You want receive already entered chars for autocomplete? I suggest you to get each key press separately. Thus, it will always be known that user have already entered.

    #include <stdio.h>


    #include <conio.h>

    Tab is '\t' and Enter is '\n'

    while ((c = getchar()) != EOF)
        if (c == '\n')
        else if (c == '\t')
        else if (c == ' ')
        if (c == EOL) {
        printf("Lines: %d\nTabs: %d\nBlanks: %d\n", newlines, tabs, blanks);