I am using the Big Nerd Ranch book Objective-C Programming, and it starts out by having us write in C in the first few chapters. In one of my programs it has me create, I us
The sleep man page says it is declared in <unistd.h>
.
Synopsis:
#include <unistd.h>
unsigned int sleep(unsigned int seconds);
What is the proper #include for the function 'sleep()'?
sleep()
isn't Standard C, but POSIX so it should be:
#include <unistd.h>
this is what I use for a cross-platform code:
#ifdef _WIN32
#include <Windows.h>
#else
#include <unistd.h>
#endif
int main()
{
pollingDelay = 100
//do stuff
//sleep:
#ifdef _WIN32
Sleep(pollingDelay);
#else
usleep(pollingDelay*1000); /* sleep for 100 milliSeconds */
#endif
//do stuff again
return 0;
}
sleep
is a non-standard function.
<unistd.h>
. Sleep
is rather from <windows.h>
. In every case, check the documentation.
sleep(3) is in unistd.h
, not stdlib.h
. Type man 3 sleep
on your command line to confirm for your machine, but I presume you're on a Mac since you're learning Objective-C, and on a Mac, you need unistd.h
.