Search code examples
cdelaycodeblockstimedelay

Does <dos.h> header file work in codeblocks?


The delay function of dos.h header file does not work in codeblocks. It shows that delay function is undeclared. the following link contains the program below. link

int main  ()
{ 
printf     (  "  This c program will exit in 10 seconds.\n");         
delay(10000);                         
return 0;
}

Solution

  • I was also having same problem & I used this function

     #include <time.h>
     void delay(int milliseconds)
     {
       long pause;
       clock_t now,then;
    
       pause = milliseconds*(CLOCKS_PER_SEC/1000);
       now = then = clock();
       while( (now-then) < pause )
         now = clock();
     }
    

    edited :

    As commented, this does make system busy. I have fund better way to do it, and works for CodeBlocks.

    #include <windows.h>
     .
     .
     .
     Sleep(100); //sleep for 0.1 second
     .