我在 Windows 上的 Code::Blocks 中使用 GNU GCC 编译器。为什么 sleep(秒) 在这里不起作用?我已经使用库尝试过,效果很好。谢谢。
编辑:“不起作用”我的意思是,无法编译。抱歉。
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[]){
char * c = (char *) malloc(sizeof(char)*50);
if(--argc>0){
printf("POTATO: \n");
while(argc>=1){
printf("- %s\n", argv[argc]);
sleep(10);
argc--;
}
printf("\n");
}
printf("A\n");
scanf("%s", c);
printf("What you wrote: %s\n", c);
scanf("%s", c);
return 0;
}
最佳答案
假设“不起作用意味着“无法编译”:
sleep()
is IX'ish 。合适win32 call would be Sleep()
。不同之处在于后者需要 ms,但需要 s,如 sleep()
那样。
要让可移植代码编写您自己的包装器,如下所示: https://stackoverflow.com/a/14818830/694576可能有帮助。
关于c - sleep() 函数不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21810273/