Thread: Time manipulation

  1. #1
    Registered User
    Join Date
    Jun 2005
    Posts
    3

    Time manipulation

    Hello

    I'd like to know how to manipulate time without freezing the program.

    I'm working on a program that time from time(the user defines the time) uses the outport, and i want to do it without freezing the program, so that the user will be able to change this time period, even while the program is waiting for this time to use the outport.

    I'm using Borland Turbo C 3.0 (Dos)

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Borland Turbo C 3.0 (Dos)
    Are you actually using DOS or just the Windows command prompt? If it's the former then you have to jump through all kinds of hoops to simulate multi-tasking. If it's the latter then you need a newer compiler, and you'll want to consider threads.
    My best code is written with the delete key.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Yet another person using some old fossil compiler, on (I'm guessing here) Windows XP (am I right?).

    Basically, you've taken your nice new ferrari, and exchanged the engine with some steam powered contraption.

    > while the program is waiting for this time to use the outport
    Modern operating systems don't allow access to the I/O ports (it's simply too dangerous in general). They instead provide a device driver to do the work for you.

    My suggestion is find a modern compiler for your modern OS, and start using the OS to do the work for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Jun 2005
    Posts
    3
    Actually I'm gonna run it in a P133, and I am wanted to do a project with this compilier, so I've thought about doing something like this to manipulate time..

    So, once for all, is there no way to do it?

  5. #5
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well time manipulation is a tricky thing. You change something in the past, and now you've just screwed up the present and future.

    That aside, it would really help if you explained better what you're trying to do.

    Let's play the "I assume this is what you meant." game!

    I assume you have a program that will run in a loop doing various tasks, some of which are based upon a "time" setting, that depending on how fast time goes by, does bigger incrementation of changes.

    In that case, all you really need to do is look up the 'kbdhit' function. This will tell when a keystroke has been hit. If it has, then you can read the keystroke that they've pressed, and update your 'time' variable as needed.

    There will of course be a delay when the input has actually been pressed, to some degree, between the time you register the keystrokes and the time you read it. Nothing is instantaneous.


    Quzah.
    Hope is the first step on the road to disappointment.

  6. #6
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Quote Originally Posted by quzah
    Well time manipulation is a tricky thing. You change something in the past, and now you've just screwed up the present and future.
    Heh...reminds me of good ole How do u control time in c++. I always enjoy seeing a thread title like that.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  7. #7
    Registered User
    Join Date
    Jun 2005
    Posts
    3
    Let me explain in a bit more detail an example for this aplication i'm looking for..

    Imagine a program wich reads from the user a time delay..

    For a example, the user sets the time 10s.

    So, every 10 seconds, this command would run:

    printf("\a");

    The matter is: the program cannot be freezed! The program must be able to run as usual, reading new values for this time delay even while the program is looping waiting for this time to beep.

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Well then you need to get rid of your old ass compiler. Then get something which will allow you to use threads, or you set up a client-server sort of thing, and use non-blocking sockets to send / read info.

    Otherwise, you can do as I described, but again no matter what, you're still going to have a bit of hesitation while it reads the keystrokes.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. Replies: 11
    Last Post: 03-29-2009, 12:27 PM
  3. calculating user time and time elapsed
    By Neildadon in forum C++ Programming
    Replies: 0
    Last Post: 02-10-2003, 06:00 PM
  4. Checking parts of a structure
    By DocDroopy in forum C Programming
    Replies: 11
    Last Post: 08-05-2002, 07:45 AM
  5. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM