Jump to content
xisto Community
khalilov

Sleep Function Not Working

Recommended Posts

/* sleep example */#include <dos.h>#include <stdio.h>int main(void){   int i;   for (i=1; i<5; i++)   {	  printf("Sleeping for %d seconds\n", i);	  sleep(i);   }   return 0;}

I have turbo C++, i found this in its help file shouldn't it work?, when i run it i get:
Compiling NONAME00.CPP:Error NONAME00.CPP 8: Call to undefined function 'sleep' in function main()

I tried library <time.h>, doesn't work. In which library is sleep() function?

Share this post


Link to post
Share on other sites

try msleep instead of sleep.
See for instance here : http://forums.xisto.com/no_longer_exists/

void msleep(long msec)
Waits for an amount of time equal to or greater than msec milliseconds. msec is a long integer.

Example:

/* wait for 1.5 seconds */
msleep(1500L);

Be careful, the argument of msleep is milliseconds, so you have to change your code.
By the way, why do you want to put it in a loop ?
Do you really want to
. sleep 1 second, then
. sleep 2 seconds, then
. sleep 3 seconds, then
. sleep 4 seconds ?
Why do you not directly sleep 10 seconds ?

Share this post


Link to post
Share on other sites
Compiling NONAME00.CPP:Error NONAME00.CPP 5: Call to undefined function 'msleep' in function main()

As for why i made that loop i just copied and pasted it =), thats how its mentioned in the help files. And it doesn't work XD

EDIT: btw i have borland turbo C++ version 4.5 if it helps, but i doubt it since like i said its mentioned in the help files and there for it must exist in this version
Edited by khalilov (see edit history)

Share this post


Link to post
Share on other sites

Seems that some libraries are missing, either physically not installed or need to be #included.Also, the msleep functions has different meanings, depending from the C version you use. This intruduces the accurante moment to talk a bout the portability guide, which defines the way of writing programs in such a way that they can be compiled on all ansi C compliant compilers.

Share this post


Link to post
Share on other sites

meh, i'll just 5.2. Iam guessing the fact that i got the program along with like 50 others for 1$ didn't help either:P. Even though the library exists its probably missing some functions.Thanks guys.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.