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

落爺英雄遲暮 提交于 2021-02-05 09:57:04

问题


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;
}

回答1:


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
 .



回答2:


i think it only works on turbo c. It is a Borland specific and works in turbo c compiler.

see link



来源:https://stackoverflow.com/questions/28128825/does-dos-h-header-file-work-in-codeblocks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!