473,806 Members | 2,236 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to write a time delay function?

Hello,
I want to write a time delay function like "Timedelay(floa t time_lenth){}".
When execute it, it will delay some seconds as long as "time_lenth "
indicating. Could you help on how to write such a function?

----------------
lovely newsgroup
----------------
Sep 8 '06
24 16142
Richard Heathfield <in*****@invali d.invalidwrites :
Keith Thompson said:

<snip>
>That's a portable way to do it, but not a good way to do it.

He didn't ask for a good way to do it. By posting in comp.lang.c, he asked
for a comp.lang.c way to do it.
No, he asked for a way to do it. If he were knowledgeable enough to
know in detail what's a comp.lang.c question and what isn't, he
wouldn't have had to ask in the first place.

People ask off-topic questions here all the time. The usual response
is to tell the OP that the question is off-topic and suggest a better
place to ask.

To someone who doesn't know C very well, it's not unreasonable to
think that the language might provide a good time delay function.

I can understand giving deliberately bad answers to "do my homework"
questions, but the OP was just looking for information.

In fact, the OP's question was very close to FAQ 19.37, "How can I
implement a delay, or time a user's response, with sub-second
resolution?".

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 8 '06 #11
"Chen Shusheng" <cs*****@gmail. comwrites:
I want to write a time delay function like "Timedelay(floa t time_lenth){}".
When execute it, it will delay some seconds as long as "time_lenth "
indicating. Could you help on how to write such a function?
The comp.lang.c FAQ is at <http://www.c-faq.com/>. See question
19.37, "How can I implement a delay, or time a user's response, with
sub-second resolution?". (Quick summary: There's no good portable way
to do this, but there are a number of system-specific solutions.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 8 '06 #12
Keith Thompson said:
Richard Heathfield <in*****@invali d.invalidwrites :
>Keith Thompson said:

<snip>
>>That's a portable way to do it, but not a good way to do it.

He didn't ask for a good way to do it. By posting in comp.lang.c, he
asked for a comp.lang.c way to do it.

No, he asked for a way to do it.
He got one. :-)
If he were knowledgeable enough to
know in detail what's a comp.lang.c question and what isn't, he
wouldn't have had to ask in the first place.
Not necessarily true. Plenty of people know what is topical in comp.lang.c
and ask topical questions.
People ask off-topic questions here all the time.
The question was not off-topic.

<snip>
In fact, the OP's question was very close to FAQ 19.37, "How can I
implement a delay, or time a user's response, with sub-second
resolution?".
True enough - although, as you clearly spotted, he actually asked for a
resolution in seconds, rather than anything finer.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 8 '06 #13
On Fri, 8 Sep 2006 17:29:00 +0800, in comp.lang.c , "Chen Shusheng"
<cs*****@gmail. comwrote:
>
My system is windowsXP. Where should I post to get the answer? Could you pls
indicate?
The very first thing you should do is search the MSDN or your compiler
documentation. Typically such functions tell are used to make your
programme "sleep". Thats a hint for the search.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Sep 8 '06 #14
On Fri, 8 Sep 2006 15:57:18 +0200, in comp.lang.c , "John F"
<sp**@127.0.0.1 wrote:
>
The things to look for are SetTimer and KillTimer...
Euh, no. but thats why we don't ask or answer system-specific
questions here.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Sep 8 '06 #15
#INCLUDE <WINDOWS.H>

....
SLEEP(1000) /*in milliseconds*/

Sep 8 '06 #16
ni*********@gma il.com writes:
#INCLUDE <WINDOWS.H>

...
SLEEP(1000) /*in milliseconds*/
No.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 8 '06 #17
ni*********@gma il.com wrote:
>
#INCLUDE <WINDOWS.H>

...
SLEEP(1000) /*in milliseconds*/
There is no such directive as #INCLUDE. You may be thinking of
#include. If so, there is no such header as <WINDOWS.H(or
<windows.h>) in standard C. After which there is no such standard
function as SLEEP() in standard C.

Standard C, as described in the various ISO standards, is the
subject of discussion here. Any peculiar non-standard systems are
OFF-TOPIC.

--
"The smaller aperture of the lid has been designed to prevent
hedgehogs from entering the McFlurry container in the
unfortunate incidence that the lid is littered"
-- McDonalds, as quoted in Time, 2006-09-11
--
Posted via a free Usenet account from http://www.teranews.com

Sep 8 '06 #18
Mark McIntyre wrote:
On Fri, 8 Sep 2006 15:57:18 +0200, in comp.lang.c , "John F"
<sp**@127.0.0.1 wrote:
>>
The things to look for are SetTimer and KillTimer...

Euh, no.
Why not? :-) It can be done. BTDT. It is as portable and standardized
as any way to achieve this...
but thats why we don't ask or answer system-specific
questions here.
*gg* I know. But if you know better, why not correct it? IMHO under
windows SetTimer and KillTimer are excellent for timing in the range
of milliseconds. They are quite precise too. I even use them in (god
help me here in c.l.c.) VB. In C there are other possibilities but I
usually write a handler for WM_TIMER and things are done. Nothing to
worry any more. If you want a delay, use a lock-variable that is set
on timer start and release it in the callback function. Highest
precision you can imagine under windoze... If you ar not satisfied yet
use the multimedia-timer - then it's even possible to do timing in the
range of µs.

All not Standard C, all not portable. It just "works". So I'll hop out
of this obviously off-topic stuff here :-)

If you want to shout at me, do so. I have no problem with it.

--
Johannes
You can have it:
Quick, Accurate, Inexpensive.
Pick two.
Sep 9 '06 #19
"John F" <sp**@127.0.0.1 writes:
Mark McIntyre wrote:
>On Fri, 8 Sep 2006 15:57:18 +0200, in comp.lang.c , "John F"
<sp**@127.0.0. 1wrote:
>>The things to look for are SetTimer and KillTimer...

Euh, no.

Why not? :-) It can be done. BTDT. It is as portable and standardized
as any way to achieve this...
>but thats why we don't ask or answer system-specific
questions here.

*gg* I know. But if you know better, why not correct it?
[snip]

Because this isn't the place for it.

Assuming SetTimer and KillTimer are specific to MS Windows, there are
a number of Windows-specific newsgroups full of people who know all
about this stuff. comp.lang.c, on the other hand, is constantly
inundated with off-topic posts; carring on off-topic technical
discussions here would only make it worse, and make things more
difficult for those of us who want to talk about C.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Sep 9 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
14871
by: gmv | last post by:
Hi, I am doing a project and i would like to know if anyone can please tell me how to write a delay or wait function in c++ which works asynchronously with other programs. Thank you, GMV
2
3680
by: notregister | last post by:
I'm to delay my program for some limited time...i try using the following codes but it doesn't work, how do i do a time delay??? 'Extracted from the main function Timer11.Start() Do tCC = timeCount Loop Until timeCount > 10000
0
1157
by: jayasakthi | last post by:
when we freeze the columns of a table in jsp, there is a time delay in scrolling the page. when we unlock the columns the time delay is not there. is there any solution for decreasing the time delay without locking the columns.
1
3685
by: klmishraa79 | last post by:
i want to know how i can put a time delay between two command execution...i.e. after first command of programm the second command should execute after some fixed delay......i want to use time delay other than sleep or timer....is it there any direct delay command like it is in c and c+...looking for ur suggestions.....thanks
9
2272
by: Martin Wells | last post by:
I'm doing an embedded systems project and I'm programming it as fully- portable C89 (except of course for setting the pin values). I need to put delays in the program, in the vicinity of 250 ms. (They don't need to be exact). Does C have a built-in method of putting in delays? If not, I was thinking of defining a macro called "FLOPS" (i.e. floating-point operations per second) and then doing something like:
1
7010
by: maul581 | last post by:
I know the delay( ) function of Turbo C and used it in my project. By this function we can give intermediate delay in execution from 1 millisecond to 9999 millisecond. My main question is "Is it possible to get delay less than 1 millisecond in Turbo C"? If by changin any header file (e.g. dos.h) or by creating my own "delay" function, at any way Can I get delay less than 1 millisecond? If in C it is not possible than please suggest me any...
3
22370
Ali Rizwan
by: Ali Rizwan | last post by:
Hello all, I want to put delay in my loops as we use in c/c++.. Is there any delay function in vb6 which put delay between any code??? Thanx >> ALI <<
2
5118
by: Rahina | last post by:
I am working in Dreamweaver 8, and I have created a simple form: http://www.realmofmystery.com/app.html This is a free website I am doing for some friends, so nothing fancy. And, I learned web design before all the CGI and PHP stuff got big, so I prefer to do things simply. The form worked fine, emails the results like perfect, but it refused to redirect the page to the confirmation. I thought I could add an onClick to the submit button,...
8
4239
by: Craig Williamson | last post by:
I'm trying to write a time delay loop in Borland C 3.1 (for legacy code) which has an accuracy of about 0.1ms. This change is due to a hardware change and the software is now running too fast to take proper readings. I have been using delay(1) in the past but it does not have the accuracy that I need for this situation. Does anyone know of a useful C function which can be used to create the time delay? If anyone could help that would...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10617
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10370
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3849
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.