0

I'm trying to use the usleep function from the unistd.h library. However, even after I included the library at the top of the function, the error still persists. Here is the error:

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$ 

Here is the code where there error is.

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

What am I doing wrong?

mfro
  • 3,286
  • 1
  • 19
  • 28
Anfernee
  • 1,445
  • 1
  • 15
  • 26
  • 1
    See this other SO question for your answer - http://stackoverflow.com/questions/7546252/what-can-i-use-besides-usleep-in-a-modern-posix-environment – pstrjds Mar 24 '14 at 21:08
  • try to compile without `std=c99` if you can – Dabo Mar 24 '14 at 21:08

1 Answers1

1

usleep() is obsolete. You could use nanosleep() or setitimer() as alternatives.

Community
  • 1
  • 1
Simon
  • 10,679
  • 1
  • 30
  • 44