[英]Implicit declaration of function 'delay' in C
I really can't understand what is wrong with my code.我真的无法理解我的代码有什么问题。 My teacher said to add
time.h
and process.h
but still doesn't work.我的老师说添加
time.h
和process.h
但仍然不起作用。 I am using TDM-GCC-64
.我正在使用
TDM-GCC-64
。 Code :代码:
#include <conio.h>
#include <string.h>
#include <process.h>
#include <time.h>
int main()
{
char str[30];
int i;
printf("Enter the string: ");
scanf("%s",str);
for(i=0;str[i]!='\0';i++)
{
printf("%c",str[i]);
delay(1000);
}
return 0;
}
There is no delay
function.没有
delay
功能。 You should use sleep
instead.你应该改用
sleep
。
So instead of所以代替
delay(1000);
do做
sleep(1); // sleep 1 second
Don't forget to include <unistd.h>不要忘记包含 <unistd.h>
If you need the delay
function you need to write it yourself.如果您需要
delay
功能,则需要自己编写。 For example the blocking version:例如阻塞版本:
void delay(unsigned milliseconds)
{
clock_t pause;
clock_t start;
pause = milliseconds * (CLOCKS_PER_SEC / 1000);
start = clock();
while( (clock() - start) < pause );
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.