Help! Need some clarification.

This is a discussion on Help! Need some clarification. within the C Programming forums, part of the General Programming Boards category; Hi, I have these ff. code: Code: /*test/dummy progam*/ #include <time.h> //var declaration clock_t start, finish; double duration; double limit ...

  1. #1
    Registered User jaro's Avatar
    Join Date
    Mar 2006
    Location
    In my Parent House
    Posts
    34

    Help! Need some clarification.

    Hi,

    I have these ff. code:
    Code:
    /*test/dummy progam*/
    
    #include <time.h>
    //var declaration
    clock_t start, finish;
    double  duration;
    double  limit = 5.00; // roughly equal to 5 seconds
    int x;
    
    int main(){
        //
        //
        //
        start = clock();
        x=1;
    
            while(1){
                finish = clock();
                duration = (finish - start) / CLOCKS_PER_SEC;
    
                if(limit < duration){
                     /* do stuff....*/      
                     printf("round %d",x++); // for example
                    start = clock();
                    duration =0.00;
                }
    
            }
    return 0;
    }
    I know that this is not resourece friendly type of code. The code above is a test/dummy program ,the program while running will execute the printf() in every 5 second.
    The test/dummy program works fine but when I try to insert this logic to the project that I'm currently working on , it does not work.
    The project mentioned here is converted/or run as a Windows service.

    I've written the test/dummy program as a Win32 console application. The project that I've mentioned is previously a Win32 console application before it is converted to run as a windows service.

    Can anyone tell me why this is happening?

    I'm Using MVC6 and my os is Win2K.

    BTW: when I tried to convert the test/dummy program run run as a Windows service, the test/dummy program does not execute - I mean does not print ( I've change the printf() to a writeToLog type of function).

    any kind of help will be appreciated.

    edit: the test/dummy program above is somewhat my solution to my previous thread A Timed Function in C


    regards,
    jaro
    Last edited by jaro; 04-06-2006 at 07:58 AM.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    I assume it's because you are setting up the unbreakable while loop and then not letting any of the Windows code execute. You may look into timer API's.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    You're supposed to use difftime() to figure out the difference between two clock_ts, not x-y.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. srand() Clarification
    By Epo in forum C++ Programming
    Replies: 2
    Last Post: 03-03-2005, 11:05 PM
  2. Need a clarification here
    By bithub in forum A Brief History of Cprogramming.com
    Replies: 30
    Last Post: 12-27-2004, 01:06 AM
  3. exercise clarification truth table
    By curlious in forum C++ Programming
    Replies: 1
    Last Post: 12-18-2003, 07:28 PM
  4. A little clarification?
    By Dr Nick in forum C++ Programming
    Replies: 2
    Last Post: 06-20-2002, 02:47 PM
  5. Clarification of Function Templates
    By biosx in forum C++ Programming
    Replies: 2
    Last Post: 02-20-2002, 11:42 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21