CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Dec 2007
    Location
    Miami, FL
    Posts
    15

    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

  2. #2
    Join Date
    Oct 2006
    Posts
    216

    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.

  3. #3
    Join Date
    Dec 2007
    Location
    Miami, FL
    Posts
    15

    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

  4. #4
    Join Date
    Jun 2004
    Location
    India
    Posts
    432

    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!

  5. #5
    Join Date
    Feb 2000
    Location
    Indore, India
    Posts
    1,046

    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.
    Let me know if I have helped by rating this post

    Recent FAQs

    Drag an image
    Area of a window exposed on desktop
    Display rotated bitmap

  6. #6
    Join Date
    Oct 2006
    Posts
    216

    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;

  7. #7
    Join Date
    Oct 2006
    Posts
    216

    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
  •  





Click Here to Expand Forum to Full Width

Featured