Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   2 tasks simultaneously in a C program (http://www.go4expert.com/forums/2-tasks-simultaneously-c-program-t2454/)

adroit89 6Jan2007 20:11

2 tasks simultaneously in a C program
 
can any one tell me how we can perform 2 tasks simultaneously in a C program.i.e.,to read a character during runtime.

DaWei 6Jan2007 20:32

Re: Help!!!
 
Use a more descriptive subject line and read the "Before you make a query" thread. Then think. Then ask what you really want to know. Most characters are read during runtime, doanchano.

shabbir 7Jan2007 07:01

Re: Help!!!
 
Quote:

Originally Posted by adroit89
can any one tell me how we can perform 2 tasks simultaneously in a C program.i.e.,to read a character during runtime.

What are the two tasks?

adroit89 7Jan2007 10:00

Re: Help!!!
 
i am making a letter fall from top to bottom of screen.during the time of fall i have to accept a character from user and check it with the letter falling.

shabbir 7Jan2007 10:29

Re: 2 tasks simultaneously in a C program
 
Edited the thread for a better heading.

shanku_4ch 7Jan2007 21:27

Re: 2 tasks simultaneously in a C program
 
actualy me & adroit r programming for individually for
TYPE WRITER GAME
in this game we r making each letters fall fall from top to bottom in a loop
but for the game we need to accept a charccter in same loop only once during the time of fall but not for each & every iteraton of loop .i hope u got us??

ever_thus 8Jan2007 19:19

Re: 2 tasks simultaneously in a C program
 
Is the letter to continue dropping while the program waits for the input? If so what you want is a multithreaded program.

I'm not going to post the complete solution here because there are many ways to do this. However I'll give you the concept. In a multithreaded program one thread does one task while another thread does another. So in this case, before you start the loop you'll start a thread ("spawn a thread" in the jargon) that asks the user for his input. When he gives it the thread terminates.

Like I said there are many ways to acheive multithreading. The simplest is to use Windows's CreateThread function (documentation available online). If you want to your program to work on other OSs you should download a C thread library. (I don't know of any I can recommend).

DaWei 8Jan2007 19:29

Re: 2 tasks simultaneously in a C program
 
Actually, you don't even need a thread. You can have character input raise an event. Neither threads nor events are a part of the C/C++ languages, so how you do this is implementation dependent.

ever_thus 8Jan2007 19:42

Re: 2 tasks simultaneously in a C program
 
True, that is a much neater way of doing it. Look here if you have VS.NET and here if you don't.


All times are GMT +5.5. The time now is 18:26.