What's the context here? A command line program reading from stdin? Or is this some graphial interfacewhere you've put up a dialog box. Or is this a cgibin program running off a web server? You need to define the problem.
For starts read "man stdio" and then read the "see also" subjects at the bottom of the page.
That said, when I read user input that a user is typing, I always like to use the "readline" library. Users kind of expect this functionality now days..