2 tasks simultaneously in a C program

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

  1. adroit89

    adroit89 New Member

    Joined:
    Jan 5, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    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

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    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

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Re: Help!!!

    What are the two tasks?
     
  4. adroit89

    adroit89 New Member

    Joined:
    Jan 5, 2007
    Messages:
    24
    Likes Received:
    0
    Trophy Points:
    0
    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

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    Edited the thread for a better heading.
     
  6. shanku_4ch

    shanku_4ch New Member

    Joined:
    Jan 7, 2007
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    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

    Joined:
    Jan 3, 2007
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    0
    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

    Joined:
    Dec 6, 2006
    Messages:
    835
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Semi-retired EE
    Location:
    Texan now in Central NY
    Home Page:
    http://www.daweidesigns.com
    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

    Joined:
    Jan 3, 2007
    Messages:
    53
    Likes Received:
    0
    Trophy Points:
    0
    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

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice