Click here to Skip to main content
14,450,441 members
Rate this:
Please Sign up or sign in to vote.
See more:
How to check one condition for every one seconds in C?

if(i>1000)
{
printf("");
}

this is the condition.. How to do it?
Posted
Comments
   
Why? And what is "i" and why do you think it may change? In different thread? So far, the question makes little sense, if any at all.
—SA
super 15-Nov-13 6:29am
   
You dont need to know what or why "i" does. He just wants to execute this method/function every one second
Sergey Alexandrovich Kryukov 15-Nov-13 10:19am
   
You don't understand. 1) This is not a method, 2) it does nothing except wasting CPU time, 3) what it does depends on "i".
Everything here just makes little to no sense.
—SA
Purevochir 11-Dec-13 3:42am
   
I is packet number
Rate this:
Please Sign up or sign in to vote.

Solution 2

Check C++ sleep for milliseconds[^] for answers depending on various OSs and/or compilers.
For Visual C++ the function you want is Sleep (included in windows.h)

P.S.: for Ubuntu Linux it should be sleep() (lowercase s) and should be included in unistd.h. see http://ubuntuforums.org/showthread.php?t=296142[^]
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 1

use
delay(1000);


to delay for desired seconds and then use your condition
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100