help

This is a discussion on help within the C Programming forums, part of the General Programming Boards category; im new to c programming. i need help im trying to get my c programs to pause for an amount ...

  1. #1
    nas
    nas is offline
    Registered User
    Join Date
    Jun 2002
    Posts
    14

    Question help

    im new to c programming. i need help im trying to get my c programs to pause for an amount of seconds and than keep going. i dont know if this is possible but if it is please tell me how.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Hm... I seem to recall something about this. Eh, it's funny how I can't quite recall where...

    There are numerious ways to do this. None of them are an ANSI standard. (IE: There is no simple pause function.) Your best bet is to simply capture the time in a loop and while the current time is less than time + N seconds, keep looping.

    Quzah.
    Last edited by quzah; 06-18-2002 at 06:57 PM.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User Azuth's Avatar
    Join Date
    Feb 2002
    Posts
    236
    Quzah, Why don't you change carreers and become a komic genius. Posts like that belong in a hall of fame.
    Demonographic rhinology is not the only possible outcome, but why take the chance

  4. #4
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    Code:
    /*
    
        Function:
        Wait(int seconds)
        
        Purpose:
        Provide a predetermined pause in the program
        giving the user enough time to read a message.
        Continue program execution after time is up
        without any user interaction.
        
        Usage:
        Wait(3) - Pauses for 3 seconds
        Wait(5) - Pauses for 5 seconds
        
    */
    
    #include <time.h>
    
    void Wait ( int seconds );
    
    void Wait ( int seconds ) 
    {
        clock_t endtime = clock() + Seconds * CLOCKS_PER_SEC;
        while ( ( clock() < endtime ) );
    }
    The world is waiting. I must leave you now.

  5. #5
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    This kind of code will only eat-up CPU resources. In a multithreaded application, this will only make things worse. The best bet is 'sleep()' (if it is supported) which will block the thread until that many number of seconds, and there will be no load at all on the CPU.

Popular pages Recent additions subscribe to a feed

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