-
December 28th, 2007, 06:00 AM
#1
What is wrong here
Code:
int main()
{
function1();
function2();
function3();
do{
functionMain();
Sleep(5000);
}
while (1 == 1);
}
functionMain(); is not executing every 5 seconds, don't know why
Please help
-
December 28th, 2007, 06:14 AM
#2
Re: What is wrong here
Does it get executed only once? What happens after that? Does the application exit? May be there is some code to exit the app inside functionMain? Just check.
-
December 28th, 2007, 06:20 AM
#3
Re: What is wrong here
every function is executed except functionMain();
no error, just the function is not executed
i want to execute functionMain() every 5 seconds
-
December 28th, 2007, 06:33 AM
#4
Re: What is wrong here
I do not see anything wrong with the code. I tried on my machine and FunctionMain should be called. How did you verify that it is not called?
On a side note, while(true) is the common paradigm for putting an infinite loop.
Say no to supplying ready made code for homework/work assignments!!
Please rate this post!
-
December 28th, 2007, 06:39 AM
#5
Re: What is wrong here
Hello,
Problem lies not in the code you have shown but somewhere else, I feel. The code modified from what you have shown
Code:
do
{
cout << "I am stuck in an infinite loop" << endl;
Sleep(5000);
}
while (1 == 1);
prints the complaint I am stuck in an infinite loop every 5 seconds till I close the program manually.
Just being curious: Why did you design it as an infinite loop?
Regards,
Pravin.
-
December 28th, 2007, 08:03 AM
#6
Initialize i
You must give some initial value to i. Do not think that it will be zero by default. If you do not initialize it, then it will have some garbage value.
Instead of just writing
int i;
write
int i = 0;
-
December 28th, 2007, 08:04 AM
#7
Did you delete?
I posted "Initialize i" in response to a post of yours. Now I do not see that post. Did you delete it?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|