doint two things at once in C
i was wandering how to write a program, that would do something (loop around) UNTIL some key is pressed, and if it is pressed, it will do something else.
for example if i wanted to write a countdown timer in C and i wish to have a 'pause' function, but i dont know how to make it to write out the time every couple of ms's and at the same time, if i press a key, to pause the timer the functions like getchar, scanf etc wait for the user to press the key.. so the coundown timer isnt working at that time i want something that would do this: do something if(key was pressed) --do sth. else else do something again |
This seems to come up a lot, lately. Your question can be rephrased as 'how do I do non-blocking character-at-a-time terminal IO?'. The answer is found in http://www.linuxquestions.org/questi...07#post2570807
--- rod. |
regarding the 'two things at once', you can use multiprocessing and signals. try to find a basic tutorial on it. the system calls would be 'kill', 'signal', and 'fork'.
if this problem isnt an urgent one, i can write an example wednesday or so.. studying for my exam tomorrow! hope it helps. |
All times are GMT -5. The time now is 12:19 AM. |