我正在学习 C。
在这个节目中
我使用 sleep 功能来减慢倒计时。
我的教科书没有指定我应该包含的库来使用 sleep 功能。
所以我使用它时没有为它包含任何特殊的库并且它可以工作。
但它在代码块中给了我这条警告信息。
我试图包括 <windows.h>
但仍然出现相同的警告消息。
warning D:\Project\C language\trial8\trial8.c|19|warning: implicit declaration of function `sleep'|
这是我的代码。
#include <stdio.h>
int main()
{
int start;
do
{
printf("Please enter the number to start\n");
printf("the countdown (1 to 100):");
scanf("%d",&start);
}
while(start<1 || start>100);
do
{
printf("T-minus %d\n",start);
start--;
sleep(3000);
}
while(start>0);
printf("Zero!\n Go!\n");
return(0);
}
我想知道警告信息是什么意思?它有多重要?有什么我应该做的吗?请注意,该程序仍然有效。
最佳答案
问题出在库(头文件)中:
在 Windows 上:
#include <windows.h>
和 Sleep(1000);
=> 1000 毫秒
在 Linux 上:
#include <unistd.h>
和 sleep(1);
=> 1 秒
关于c - sleep |函数 `sleep' 的警告隐式声明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39156743/