Thread: double Execution in C ?????

  1. #1
    Registered User
    Join Date
    Dec 2010
    Location
    Lucknow, India
    Posts
    72

    double Execution in C ?????

    Hi. how to make Double Execution in C..????
    I just write a Code of a moving Car in a fixed direction..
    now i just want to make it move in multi directions.
    Suppose if it is moving from Left to right and when user press a defined key the car start moving in another direction. But the Problem is that wherever I use any function to take input like scanf() or getch().. they holds the Screen and wait for Input.. i just want that the compiler should wait for a Second and if there is no INPUT then it just Skip that line.

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You mentioned getch(). Does that mean your compiler is Turbo C?

    If it is, you can use logic like this untested idea code:

    Code:
    include conio.h and stdio.h
    
    int etime = 0;
    while(!keybd() & etime <3000) {
      etime += 100;
      delay(100);
    }
    If you're running on Linux, then you'll need to use the Ncurses extensions, which are similar. If you're on Windows, and not using Turbo C, then you can do it using the Windows API, which is however, substantially different.

  3. #3
    Registered User
    Join Date
    Aug 2010
    Location
    Rochester, NY
    Posts
    196
    It looks like you're making a game of sorts, in which case the GUI framework typically catches the keypresses. Regardless, look into non-blocking interrupts, non-blocking input.

    EDIT:
    Many programs with GUI frameworks will use a separate thread running in a task loop to grab interrupts and throw them on an event queue, then a separate task loop will keep iterating, popping stuff off of the queue while it's not empty and dealing with the keypresses. This creates a form of buffered, non-blocking, input to the program, which is what you kind of need in a real time game.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Travel Expenses-Weird Result
    By taj777 in forum C++ Programming
    Replies: 4
    Last Post: 04-06-2010, 02:23 PM
  2. Error in printf line,,,what's wrong?
    By mft_ika in forum C Programming
    Replies: 9
    Last Post: 03-19-2010, 08:46 PM
  3. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  4. Copying 2-d arrays
    By Holtzy in forum C++ Programming
    Replies: 11
    Last Post: 03-14-2008, 03:44 PM
  5. functions and passing data
    By redmondtab in forum C Programming
    Replies: 41
    Last Post: 09-21-2006, 12:04 PM