c - 为什么我会收到错误 (C)?

标签 c include declaration

我正在尝试使用 unistd.h 库中的 usleep 函数。但是,即使我将库包含在函数顶部之后,错误仍然存​​在。这是错误:

anfernee@AJ-crunchbang:~/Dropbox/CSCAPE/Tesla$ make calculator
clang -ggdb3 -O0 -std=c99 -Wall -Werror -lm -lcs50    calculator.c   -o calculator
calculator.c:20:2: error: implicit declaration of function 'usleep' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
        usleep(180000);
        ^
1 error generated.
make: *** [calculator] Error 1
anfernee@AJ-crunchbang:~/Dropbox/CSCAPE/Tesla$ ^C
anfernee@AJ-crunchbang:~/Dropbox/CSCAPE/Tesla$ 

这是出现错误的代码。

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

#define CLEAR printf("\033[2J");printf("\033[%d;%dH", 0, 0); //creates a constant that clears the console screen


void PResistance(void); //calculates total resistance with resistors in parallel
//void Truth(void); //determines the truth table for logic gates specified
void EForce(void); //Calculated the electric force
void Ohm(void); //calculates power

int main(void){
    int option; //Stores the user's option 
    int exit = 0;
    printf("\033[0;36;40m"); //Changes the colour of screen to cyan 
    printf("Welcome!\n"); //greet user

    usleep(180000);

我做错了什么?

最佳答案

usleep() 已过时。您可以使用 nanosleep()setitimer()作为替代方案。

关于c - 为什么我会收到错误 (C)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22620570/

相关文章:

c - 在 C 中保存 16 位二进制数据类型

javascript - AngularJs 加载需要的脚本

C:使用链表向结构添加数据

c - 线程变化的开始已经设置了全局变量

c++ - 当类包含在另一个类中时,为什么不转发类工作的声明

javascript - 有什么方法可以在javascript中包含条件吗?

C++ 错误 : Member declaration not found

c++ - 局部变量的声明和初始化——大多数 C++ 是什么样的?

c - 为什么枚举数据类型总是在 c 中的 main() 之外声明?

c++ - int32 溢出后可能的值是多少?