Two function running at the same time

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
In the while just check for a key press and stop the loop if the key was pressed.
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
uh, i think it has to be multiple thread
Is there not a method to detect a key press without getting input from the user? ;)
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.
Thank you very much...
Topic archived. No new replies allowed.