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.
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;
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With