Two function running at the same time

Aug 25, 2010 at 11:41pm
Hi guys i have question.
i want to run two function at the same time.
For example:


1
2
3
4
5
6
#include <stdio.h>
int main () {
int a;
while (a!=5)  printf("hasan"); /* i want to when program writes, i enter a decimal to stop writing*/ 
scanf("%d",&a);
return 0;}
Last edited on Aug 26, 2010 at 2:12am
Aug 26, 2010 at 12:42am
In the while just check for a key press and stop the loop if the key was pressed.
Aug 26, 2010 at 2:15am
Thank you but when program is running, it writes "hasan" to infinite.
if i put scanf in {,,,}, it waits for n input.
I want to both program writes and i can enter anything
Aug 26, 2010 at 2:22am
uh, i think it has to be multiple thread
Aug 26, 2010 at 2:27am
Is there not a method to detect a key press without getting input from the user? ;)
Aug 26, 2010 at 2:59pm
There are methods, but they are all OS-dependent.

For Windows: http://www.cplusplus.com/forum/beginner/5619/#msg25047

Here is similar code for POSIX (Linux, etc): http://www.cplusplus.com/forum/general/5304/page1.html#msg23940
(It will need to be massaged a bit to do the exact same thing as the Windows code does, but the how-to is there.)

Oh, thinking of how-tos, there's also this thread:
http://www.cplusplus.com/forum/articles/7312/#msg33734

Hope this helps.
Aug 26, 2010 at 6:54pm
Thank you very much...
Topic archived. No new replies allowed.