Originally Posted by
fguy817817
I'm not receiving the raw keystrokes. Currently I have written my own version of scanf() that uses fgets() to accept keyboard input. I have never used the keyboard buffer before. Considering the number of shells that contain an autocomplete feature, I was thinking there was a standard way of doing this type of manipulation.
I don't know what the shells are using, but I imagine at the least they have to change the buffering of stdin. One thing to be aware of with my previous suggestion:
Code:
tabstop@ubuntu:~/helping$ cat chars.c
#include <stdio.h>
#include <stdlib.h>
int main(void) {
printf("Prompt: ");
ungetc('2', stdin);
ungetc('1', stdin);
char answer[80];
fgets(answer, sizeof(answer), stdin);
printf("%s\n", answer);
return 0;
}
tabstop@ubuntu:~/helping$ ./chars
Prompt: 3
123