Delays are often require in a program. Some examples are like -

  1. Polling for a status bit for a reguler interval
  2. Printing strings with delay in between to animate it
  3. Printing some bitmaps with delay in between to create a slide show effect
  4. Playing different sounds with intervals
  5. Stall the execution for ever till some signal/event comes

Many other combinations are possible in games and animation programs. So delay/sleep API library function can be used for this.

We should remember that delay is handled in task scheduler and thus it is operting system dependent. Followings are ways to execute delays in Windows, Linux and DOS.

Windows:
#include <windows.h>
VOID WINAPI Sleep(
  _In_  DWORD dwMilliseconds
);
Linux:
#include <unistd.h>
unsigned int sleep(unsigned int seconds);
DOS:
#include <process.h>
VOID WINAPI delay(
  _In_  DWORD dwMilliseconds
);

About our authors: Team EQA

You have viewed 1 page out of 252. Your C learning is 0.00% complete. Login to check your learning progress.

#