Nov 8, 2009

Sleep Function Not Working

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Programming General > C, C++ & Visual C++

Sleep Function Not Working

khalilov
CODE
/* 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:
CODE
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?

Comment/Reply (w/o sign-up)

yordan
try msleep instead of sleep.
See for instance here : http://www.handyboard.com/software/icmanual/node86.html
QUOTE
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 ?

Comment/Reply (w/o sign-up)

khalilov
CODE
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

Comment/Reply (w/o sign-up)

zorba4
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.

Comment/Reply (w/o sign-up)

khalilov
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.

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Function Working

  1. Password Function - (0)
  2. Alternative To Strtok() Function In C++ - (1)
    Hello, i have written an alternative function to strtok(), which i think is better and easier to
    use. I hope it will be usefull. Here is the code snippet from my program: CODE      1 /*      
                 2  * The Ultimate Network Tool.      3  * Copyright (C) 2004 Virtual Pointer      4
     *      5  * The Ultimate Network Tool is free software; you can redistribute it and/or      6  *
    modify it under the terms of the GNU General Public License      7  * as published by the Free
    Software Foundation; either      8  * version 2.1 of the License, or (at your opt...
  3. C++ Console/dos Based Calendar - Working Calendar for Linux/DOS (0)
    Decided to have it's own Thread Here's a fully functional console calendar I wrote using
    pdcurses/ncurses, it was based off a Windows version calendar, but I ported what I could to Linux,
    still missing some functionality from the Windows version by stoned coder, but I hope to get that
    sorted. CODE // calendar.cpp by mastercomputers // includes #include  // contains our console
    objects #include  // contains our string manipulation objects // classes class calendar { public:
        calendar(int d = 1, int m = 1, int y = 2004); // defaults to 1/1/2004 (nz f...



Looking for sleep, function, working

See Also,

*SIMILAR VIDEOS*
Searching Video's for sleep, function, working
advertisement



Sleep Function Not Working

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com