Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



sleep() function in C

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 03-03-2010
Member
 
Join Date: Dec 2009
Posts: 296
sleep() function in C
  

I have created a program which prints the string from the array one character at a time.I think to use a sleep function within the for loop. But occurs the error regarding the header file.I need to know the actual functionality of the sleep function and how it would be constructed in the program.

thanks.

Reply With Quote
  #2  
Old 03-03-2010
Member
 
Join Date: Apr 2008
Posts: 2,000
sleep() function in C

sleep() function in C

The sleep is one of the most useful function in C and also used in C++.It provides the delay of execution for a specified time interval depends on the allocated time.The function takes the following form and stored in the time.h header file.

Sleep(Duration);

Where the duration describes the time (sleep call in milliseconds) till the execution would be stopped or delayed.
Reply With Quote
  #3  
Old 03-03-2010
Member
 
Join Date: May 2008
Posts: 2,290
Problem with sleep function in C

Problem with sleep function in C

If you are getting some problem during the execution of the program then you need to check the whole program for any syntactical error.

You specified that the error is generated from the Header file.If the function is not identified by any header file then you need to use the TIME.H header file in the header definition section of the program.

#include <time.h>

and check also you are calling the procedure in different way or the variables which is being used by the program is exist or not.
Reply With Quote
  #4  
Old 03-03-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
Example of sleep function in C

Example of sleep function

The sleep function can be structured with a program.As you suggested above from the members and experts,It stops the execution of the program for a specified time interval.

Here,a code is shown which stops the execution of the program for 1 second -

Code:
#include <time.h>
#include <stdio.h>
#include <conio.h>

int main()
{
   printf("This is Msg_1 \n");
   sleep(1000); //1000 microsecond= 1 second will sleep...
   printf("This is Msg_2 after  1 second.......");
   getch();
   return 0;
}
Reply With Quote
  #5  
Old 03-03-2010
Member
 
Join Date: May 2008
Posts: 2,382
SLEEP function behavior on different platform

There are some places where we can use this function and they have same functionality but have different syntax and arguments.

The SLEEP function is being used on windows and POSIX compliant systems but the declaration on both places is different from each other.

Declaration on POSIX compliant systems

sleep(time_in_second)

Declaration on windows system

Sleep(time_in_milisecond)

The difference of the S word in both declaration are also separate.
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #6  
Old 03-03-2010
Member
 
Join Date: Feb 2008
Posts: 1,845
SLEEP declaration on POSIX

SLEEP declaration on POSIX

The declaration of sleep function on POSIX is something different from the windows compliant.The sleep command rejects or stops the execution for time seconds.

(sleep 105; command)&

or if you need to run a command every so often then you can do it as follows-

Code:
while true
   	do
   		command
   		sleep 37
   	done
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "sleep() function in C"
Thread Thread Starter Forum Replies Last Post
Sleep timer function repeatedly switches off in Sansa Clip+ Li-One Portable Devices 3 27-01-2012 10:43 AM
Sleep function for Logitech Harmony 525 Devabrata Hardware Peripherals 6 10-06-2010 06:39 AM
How to write pause, sleep, wait function VinFanatic Software Development 3 07-07-2009 03:36 PM
JavaScript Sleep Function DARIELLE Software Development 3 29-06-2009 09:30 AM
How to Interrupt Sleep Function in Python Xena Software Development 3 13-04-2009 03:08 PM


All times are GMT +5.5. The time now is 12:29 AM.