need a similar function as "getchar()"
-
if I am using getchar(), then the execution of the program will stop here if no input is given. could someone help me figure out if there is another way? Aim: while any input is given, save it to a variable, if not, keep on executing program without stop. I have used multithread, but it did not work well when I put it running at background. I am using C
-
if I am using getchar(), then the execution of the program will stop here if no input is given. could someone help me figure out if there is another way? Aim: while any input is given, save it to a variable, if not, keep on executing program without stop. I have used multithread, but it did not work well when I put it running at background. I am using C
-
not necessarily a single function, but with the usage: keep program running, while accept the input if any
-
not necessarily a single function, but with the usage: keep program running, while accept the input if any
-
if I am using getchar(), then the execution of the program will stop here if no input is given. could someone help me figure out if there is another way? Aim: while any input is given, save it to a variable, if not, keep on executing program without stop. I have used multithread, but it did not work well when I put it running at background. I am using C
-
What about multithreading? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
I had been used multithread, and it works strange. It works fine when I run the program at foreground, the first thread keeps running while the second thread waiting for input. But it does not work well when I run it at background. Without any inputs, both the first and second threads will stop. Only after I manually switching it back to run at foreground, then the first thread runs again. So I really want to find something similar and simpler than the mulithread way.
-
if I am using getchar(), then the execution of the program will stop here if no input is given. could someone help me figure out if there is another way? Aim: while any input is given, save it to a variable, if not, keep on executing program without stop. I have used multithread, but it did not work well when I put it running at background. I am using C
-
if I am using getchar(), then the execution of the program will stop here if no input is given. could someone help me figure out if there is another way? Aim: while any input is given, save it to a variable, if not, keep on executing program without stop. I have used multithread, but it did not work well when I put it running at background. I am using C
my quick input before lunch if(kbhit()) { //get with getchar() } continue code... kbhit() will solve the problem off the top of my head, cant remember if its part of stdio or another header file... will look after lunch for you :) modified: its in conio.h _kbhit returns 0 if no key has been pressed, otherwise a nonzero int if has. -- modified at 6:27 Wednesday 11th July, 2007
-
if I am using getchar(), then the execution of the program will stop here if no input is given. could someone help me figure out if there is another way? Aim: while any input is given, save it to a variable, if not, keep on executing program without stop. I have used multithread, but it did not work well when I put it running at background. I am using C
An alternative way is to use the select() call (only if you use linux/unix platform). select will wait for a file descriptor to become active and read the data from this file descriptor. I assume you can establish a pipe interface with STDIN and then use select to monitor your fd. you can put select in a while loop to monitor the fds continuously and maybe fork() this function if you want control back...