ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
I am a university student doing a project on uClinux Coldfire boards. I am faced with a daunting yet simple problem which I can't get my head around.
Is there any way for me to check for user input when inside a while loop? If the user hasn't inputed anything then the while loop just continues. Basically I want the user to be able to terminate the while loop.
At the moment scanf and other similar functions that I know wait for user input. There is no timeout.
Does anyone know of a better alternative than this. I can't really fork out a new process because of uClinux only supports vfork.
... i've never used c in practice, so i may be wrong, but maybe you could test stdin against true or false and so decide if there was any input. on second taught, there really must be an option to read (a byte) directly from stdin, and it should be zero if no input.
but... ...you never know
Use select() for this. Add STDIN in the read list of select and set the timer value to 0. This way when the the application will come to select(), it will simply check if the there in some input. If there is not input if will immidiately go forward.