Question

I'm trying to do add an advanced feature to my command line program that when you press the 'Tab' button it suggests what word you might mean (In the context of files, bash has this feature when you press tab it prints matching filenames on the next line).

Below is a snippet of what I have. I've replace the '\n' with the ASCII for tab (to see if it works) but i sill need to press the enter key for data to be directed to Standard In.

Any help is appreciated. Thanks.

    while (1){
        c = getchar() ;
        if (isspace(c)){
            curLine[pos]='\0';
            buffer[w_count] = curLine ;
            ++w_count;
            pos=0;
            curLine = calloc(10, sizeof(char));
            if (c == '\n')
                break;
            }
            curLine[pos]=c;
             ++pos;
        }
    }
Was it helpful?

Solution

Use gnu readline library and refer sample example of readline library at http://www.delorie.com/gnu/docs/readline/rlman_48.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top