Q57946: An Example of a delay() Function in C 5.10 or QuickC 2.00
Article: Q57946
Product(s): See article
Version(s): 2.00 2.01
Operating System(s): MS-DOS
Keyword(s): ENDUSER | S_C | mspl13_c
Last Modified: 7-MAR-1990
The Microsoft C or QuickC run-time library does not include a delay()
function. The sample code below demonstrates a function that could be
used to generate a delay within a program.
Sample Code
-----------
#include <stdio.h>
#include <time.h> /* needed for delay() */
void delay (clock_t ms); /* prototype for delay() */
void main (void)
{
puts("This is a test of a delay function.");
delay(5000); /* 5 second delay */
puts("Back from delay function.");
}
void delay (clock_t ms)
{
clock_t stop;
stop = ms + clock();
while(stop > clock());
}
The delay() function generates a delay in milliseconds. For example,
to have a 10 second delay, pass the value 10000 to the function.
THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.
Copyright Microsoft Corporation 1986-2002.