Question:
C Sleep function header file help?
Brad Cross
2012-01-22 12:20:28 UTC
I cant seem to find the right header file, apart from the obvious header files, the rest dont work, here is the exact code ( it was a test ) :
#include
#include
#include
#include
#include
#include
#include
#include

int main()
{
printf("This is Msg_1 \n");
sleep(1000); // here is my problem :(
printf("This is Msg_2 after 1 second.......");
getch();
return 0;
}

what header files do i need ?

OS : Windows 7 Home Premium x86
Computer Type : x86
Seven answers:
longacre
2016-12-14 11:59:39 UTC
Sleep Function C
chritton
2016-10-04 12:23:26 UTC
C Sleep Function
Mary
2016-04-03 10:41:37 UTC
For the best answers, search on this site https://shorturl.im/axTsY



WIthin c language you have can do functions as define within the header file. For instance: #if defined(linux) || defined(__APPLE__) # if !defined(TRUE) # define TRUE 1 # endif # if !defined(FALSE) # define FALSE 0 # endif # if !defined(max) # define max(a,b) (((a) > (b)) ? (a) : (b)) # endif # if !defined(min) # define min(a,b) (((a) < (b)) ? (a) : (b)) # endif # if !defined(MB_OK) # define MB_OK 0 # endif # if !defined(Sleep) # define Sleep(x) usleep((x) * 1000) # endif #endif /* linux || __APPLE__ */ Or you could do something like this which is a macro. #define TEST_DEVICE(X) (((X).errorCode) != HD_SUCCESS) So usually within header files we just include typedefs, defines, and functions. IF we include functions, then in the main class we implement those functions. Think of it as a interface. For instance: index.h ================================= void hdBeginFrame(int hHD); void hdEndFrame(int hHD); index.c ===================== void hdBeginFrame(int hHD) { ..... } So instead of declaring the functions in your .c file at the beginning , you could do them within the header file. IT acts as a interface in other languages. The reason why we have .h files is simple portability. When developers compile their code or module into dlls or so objects and they want their clients to use them, they can check the .h files to see which functions are included within that dll. That is how we can do it. :)
jplatt39
2012-01-22 12:59:29 UTC
It's more compiler dependent than OS dependent but you will find it in GCC in unistd. I'm writing this on Slackware Linux and I just went looking and got:



bash-4.1$ grep sleep /usr/include/unistd.h

/* Make the process sleep for SECONDS seconds, or until a signal arrives

SIGALRM signal while inside `sleep' call, the handling of the SIGALRM

error, but if `sleep' returns SECONDS, it probably didn't work.

extern unsigned int sleep (unsigned int __seconds);

extern int usleep (__useconds_t __useconds);

bash-4.1$





Grep is a program for UNIX and Linux which finds a string in a given file. You might search unistd.h in your compiler, but it can be in other files.
latrice
2016-06-20 07:12:29 UTC
Sleep Function C
2012-01-22 13:05:31 UTC
You dont need repeats of those headers, for one.



Beware with conio.h. If you are going to use it, use it for its purposes: roguelike gaming.



Otherwise, all you need to do is:



Sleep(x); with a capital S. Otherwise it wont work.



Hope this helped!
2012-01-22 12:45:43 UTC
#include

#include /* For Sleep() */



int main(void)

{

        printf("This is message one\n");

        Sleep(1000);

        printf("This is message two\n");

        return 0;

}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...