Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sleep | warning implicit declaration of function `sleep'?

Tags:

c

sleep

windows

I am learning C. In this program I use sleep function to slowdown a count down. My text book doesn't specify a library I should include to use the sleep function. So I use it without including any special library for it and it works. But it gives me this warning message in codeblocks. I tried to include <windows.h> but still the same warning message appears.

warning D:\Project\C language\trial8\trial8.c|19|warning: implicit declaration of function `sleep'|

And here is my code.

#include <stdio.h>
int main()
{
    int start;

    do
    {
        printf("Please enter the number to start\n");
        printf("the countdown (1 to 100):");
        scanf("%d",&start);
    }
    while(start<1 || start>100);

    do
    {
        printf("T-minus %d\n",start);
        start--;
        sleep(3000); 
    }
    while(start>0);
    printf("Zero!\n Go!\n");
    return(0);
}

I want to know what does the warning message mean? How important is it? Is there anything that I should do about it? Note that the program works anyway.

like image 894
Allan Mayers Avatar asked Aug 26 '16 00:08

Allan Mayers


1 Answers

Update in 2022:

As it is stated on the Linux man page https://linux.die.net/man/3/sleep we need to include unistd.h and should do fine for all OS.

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

int main()
{

  sleep(1); /* sleep for 1 second*/
  printf("END\n");
  
  return 0;
}
like image 89
Mohamad Ghaith Alzin Avatar answered Oct 29 '22 00:10

Mohamad Ghaith Alzin