Thread: delay

  1. #1
    Unregistered
    Guest

    Lightbulb delay

    Hi

    I'm seraching for a tutorial where "delay" is explained. I have already looked up in serveral books but I can`t find.

    thanks

    my e-mail: [email protected]

  2. #2
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    The function delay is not part of ANSI C. But you can use the time functions to do something like that, or find a special function your compiler supports.

    http://www.acm.uiuc.edu/webmonkeys/book/c_guide/

  3. #3
    Registered User lliero's Avatar
    Join Date
    Oct 2001
    Posts
    59

    you

    you can delay a certain portion of your program
    by implementing a loop


    e.g

    myDelay(){
    for (i=0;i=100000;i++){ // this will delay for some time
    }
    }
    " programming is 1% syntax and 99% logic "

  4. #4
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    Note that lliero is machine dependent.

  5. #5
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Note that lliero is machine dependent.
    Yes, depending on the processor speed of the machine running that code it will take more or less time to complete the loop. This function will work a bit more portably.
    Code:
    #include <time.h>
    
    void delay ( long n )
    {
      clock_t l, c = clock();
      for ( l = c + n; l > c; c = clock() );
    }
    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Regarding delay in the connection
    By byatin in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-19-2008, 02:59 PM
  2. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  3. Networking (queuing delay, avg packet loss)
    By spoon_ in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-05-2005, 11:23 AM
  4. 2-3 Second delay with alarm()
    By Longie in forum C Programming
    Replies: 11
    Last Post: 06-20-2004, 08:46 PM
  5. Delay
    By CanadianOutlaw in forum C++ Programming
    Replies: 4
    Last Post: 09-13-2001, 06:28 AM