Results 1 to 6 of 6

Thread: Which file to include using sleep()?

  1. #1
    Join Date
    Nov 2009
    Posts
    37

    Which file to include using sleep()?

    Hi friends,
    I am last year computer science student. I recently started learning c++ language. In one of my code I tried to use sleep() method to make my program to take a break, but I don't know which file to include using sleep()?. I tried to use <stdlib.h>, but it doesn't work. Can anyone help me to fix this problem.
    Thanks in advanced.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Which file to include using sleep()?

    Hey you have use wrong header in your code and that's why you are getting such type of problem. You have use "stdlib.h" instead of "windows.h" and that's why your program is not running. In this case use "windows.h" in your header. You also have use make one silly mistake, your function start with a small "s". Just make it capital like Sleep(1500) to fix this problem.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: Which file to include using sleep()?

    Hey you have to use "time.h" file in your sleep() function to get rid out of this problem. I have written following code for you. Just try to understand this. It is very simple code. I have pass one object known as "times_ts delay" to sleep() function to fix this problem.
    Code:
    void sleep( times_ts delay )
    {
    times_ts timers0, timers1;
    times( &timers0 );
    do
    {
    times( &timers1 );
    }
    while (( timers1 - timers0 ) < delay );
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Which file to include using sleep()?

    The sleep() function is used to suspends execution for an interval. When you call sleep() function in your program, the current running program is suspended from execution for the few seconds which is specified by the argument seconds. I have written following program using sleep() function. Just try to understand this.
    Code:
    #include <dos.h>
    #include <stdio.h>
    #include <conio.h>
    
    int main()
    {
       printf("Messages are 1\n");
       sleep(3); 
       printf("Message "welcome" three seconds after Message "End" ");
       getch();
       return 0;
    }

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: Which file to include using sleep()?

    As per my knowledge sleep() function is used to suspend execution of an program for an interval of time. To use this function you have to first import "unistd.h" header in your program and after this you have to use sleep() function. You can do this in following ways.
    Code:
    #include <unistd.h>
    unsigned sleep(unsigned seconds1);

  6. #6
    Join Date
    Nov 2005
    Posts
    1,323

    Re: Which file to include using sleep()?

    I have written following code for you using sleep() function. This is very simple code. Just try to understand this code. In the following code I have use iostream class to include all input and output method. I also have use windows.h class to use sleep() function.
    Code:
    #include <iostream>
    #include <windows.h>
    
    using namespace std;
    
    int main()
    {
    int k;
    for(k=0; k<1000+1; k+=1)
    {
    system("CLSEG");
    cout << k << endl;
    Sleep(1000);
    }
    return 0;
    }

Similar Threads

  1. How do I include one file inside another in HTML?
    By Ekavali in forum Software Development
    Replies: 4
    Last Post: 19-08-2010, 01:38 PM
  2. JNI - Cannot open include file: 'jni_md.h
    By rav1 in forum Software Development
    Replies: 5
    Last Post: 07-08-2010, 02:51 AM
  3. How to include the video file in Html
    By Owen Fernandes in forum Software Development
    Replies: 5
    Last Post: 29-12-2009, 11:40 AM
  4. Will backup include viruses infected file!! Help urgent
    By cheap_kaspersky in forum Windows Software
    Replies: 8
    Last Post: 05-07-2009, 02:17 PM
  5. include port in hosts file
    By John A Grandy in forum Windows Server Help
    Replies: 2
    Last Post: 15-04-2009, 07:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,030,582.24407 seconds with 17 queries