“睡眠”的冲突类型

时间:2014-05-01 05:55:03

标签: c

当我尝试运行程序时,为什么一直收到错误消息“'睡眠'的冲突类型”?

#include <stdio.h>
#include <stdlib.h>

void congratulateStudent (char *student, char *course, int numDays)
{
    printf("%s has done as much %s Programming as I could fit into %d days. \n", student, course, numDays);
}

int main(int argc, const char * argv[])
{
    congratulateStudent("Mark", "Cocoa", 5);
    sleep(2);
    congratulateStudent("Bo", "Objective-C", 2);
    sleep(2);
    congratulateStudent("Mike", "Python", 5);
    sleep(2);
    congratulateStudent("Ted", "iOS", 5);

    return 0;
}

1 个答案:

答案 0 :(得分:6)

每个库函数都有一个相应的头文件来声明该函数。对于sleep函数,该头文件为unistd.h。每个函数的文档都会告诉您使用哪个头文件。

如果您没有包含正确的头文件,那么编译器会抱怨。不要让编译器不高兴,总是包含正确的头文件。