Thread: How program run predefine time?

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    16

    How program run predefine time?

    How could I make my program to run in predefined time automatically in c?

  2. #2
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Depends on the platform. Most implementations provide a sleep function of some sort, so you tell your program to wait the required number of seconds until the time arrives, then run the program.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    16
    thank to help me. Can u give me the code then I could lear it better.

  4. #4
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Sure. Let's say it's 5:00pm now, and you want to run your program at 6:37:43am the following day:
    Code:
    sleep(49063);
    system("myprogram");

  5. #5
    Registered User
    Join Date
    Dec 2005
    Posts
    16
    thanks for the help.I hope your help can inprove my depth in c & c++ too

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Most decent operating systems have some kind of 'at' function which allows you to specify a time at which a program should be run.

  7. #7
    Registered User
    Join Date
    Dec 2005
    Posts
    16
    Thanks for the interest.
    But I want to know how a user written program(made in c) will run automatically in predefined time. I want to add the c code to run my program automaticaly.Can u tell
    me about that?

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Sure, look up the time(), localtime(), mktime() and difftime() functions.

    - Find out the time now
    - Work out the time you want to run at
    - Get the difference between the two
    - Sleep for that amount

  9. #9
    Registered User
    Join Date
    Dec 2005
    Posts
    16
    thanks 4 help.
    Can u give a example code pls?

  10. #10
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    You're going to need to do a little better than that. You've been pointed to the appropriate functions and the steps involved, go look them up, read about them, attempt to come up with a solution, and we'll help you when you get stuck, after you've posted a good attempt.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 10:42 AM
  2. Cannot run program in background?
    By registering in forum Linux Programming
    Replies: 3
    Last Post: 06-16-2003, 05:47 AM
  3. inputting time in separate compilation
    By sameintheend01 in forum C++ Programming
    Replies: 6
    Last Post: 03-13-2003, 04:33 AM
  4. I apologize. Good bye.
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM
  5. Trying to make rand different per program run
    By Dreamerv3 in forum C++ Programming
    Replies: 6
    Last Post: 01-18-2002, 03:26 AM