sleep()函数不工作?

时间:2014-02-16 11:04:08

标签: c linux windows sleep

我在Windows上的Code :: Blocks中使用GNU GCC编译器。为什么不睡觉(秒)在这里工作?我已经尝试使用库,它工作正常。感谢。

编辑:通过“不起作用”我的意思是,不编译。遗憾。

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

2 个答案:

答案 0 :(得分:4)

假设“不起作用表示”无法编译“:

sleep() is IX'ish。适当的win32 call would be Sleep()。区别在于后者需要ms,但是s,sleep()


要让可移植代码编写自己的包装器,如下所示:https://stackoverflow.com/a/14818830/694576可能有所帮助。

答案 1 :(得分:0)

因为命令行参数argc是1.所以如果条件不起作用, 在if()条件之前使用print语句。