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 would like to compile it on a windows system to run on windows so I can share it with one of my kids - one of those windows user people.
I put up a prompt and then wait till either the user answers or it times out.
I do that using a POSIX feature - a call to "select" .
I understand that POSIX features are not typically supported on windows.
Can someone familiar with c and windows - command line - not graphical - tell me how to wait either for input on stdin or till n seconds pass, using a feature that windows supports ?
Windows (Visual Studio) supports select, I use it all the time. Porting code from Linux over to Windows is fairly easy. Porting from Windows to Linux can be tougher if the program is coded using Windows-isms (Functions that are specific to the Windows platform and may or may not have corresponding Linux functionality). If you stick to the Linux APIs, your should be okay when porting the code over to Windows.
Also, you could get the cygwin IDE instead of using Visual Studio.
rstewart
i just tried it and did not succeed - I downloaded the free 30 day version of visual
heres what i have in linux
#include <unistd.h>
...
#include <sys/time.h>
...
return TEMP_FAILURE_RETRY (select (FD_SETSIZE,
&set, NULL, NULL,
&timeout));
...
it complained about the three lines above + and others defined in the h files
on linux it is a c program - i note that in visual everything is c++
maybe i need different header definitions?
Windows defines some POSIX functions, but not all and they are often in different header files. It does have select, but I'm pretty sure it's only for sockets; you can't use it to test stdin.
You may be able to use WaitForSingleObject, although there is a comment on that page:
Quote:
Originally Posted by Medinoc
Make sure to disable the ENABLE_LINE_INPUT console mode before waiting on a console input buffer object.
Regardless of the mode, console input buffer objects are signaled as soon as a character is typed, while the reading functions will block until the line is finished, voiding the purpose of a dedicated, time-limited wait function.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.