ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
Yes, select() is what you're looking for.
It is a bit of a tricky function to use, though.
So, apart from "man select" itself, you may want to read "man select_tut".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.