1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

2 tasks simultaneously in a C program

Discussion in 'C' started by adroit89, Jan 6, 2007.

  1. adroit89

    adroit89 New Member

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

    DaWei New Member

    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.
     
  3. shabbir

    shabbir Administrator Staff Member

    Re: Help!!!

    What are the two tasks?
     
  4. adroit89

    adroit89 New Member

    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.
     
  5. shabbir

    shabbir Administrator Staff Member

    Edited the thread for a better heading.
     
  6. shanku_4ch

    shanku_4ch New Member

    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??
     
  7. ever_thus

    ever_thus New Member

    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).
     
  8. DaWei

    DaWei New Member

    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.
     
  9. ever_thus

    ever_thus New Member

    True, that is a much neater way of doing it. Look here if you have VS.NET and here if you don't.
     

Share This Page