Thread: System call to pause execution of a program for a few seconds

  1. #1
    Registered User
    Join Date
    Jan 2014
    Location
    Los Angeles, California, United States
    Posts
    14

    System call to pause execution of a program for a few seconds

    I know there has to be a system call to pause (not system("pause") execution of a program for a few seconds. I would like to give the illusion that my program is 'thinking' rather than just spit out the result as soon as the user has hit the enter key.

    Can anyone clue me in on this??

    Many thanks in advance!!

  2. #2
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    You can try looking for "wait" or "delay" type function. Or you can write a loop that queries the system time until it elapses some interval from a start point.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Looping while continuously asking for the system time will waste many CPU cycles and power. Better to use sleep or usleep in this situation.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    For Windows, include windows.h and then use Sleep(microsecondsYouWantHere)

  5. #5
    Registered User
    Join Date
    Jan 2014
    Location
    Los Angeles, California, United States
    Posts
    14

    Perfect! Many thanks !!

    Quote Originally Posted by Adak View Post
    For Windows, include windows.h and then use Sleep(microsecondsYouWantHere)
    Didn't know about the header file, Thanks!!

  6. #6
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    Note that the parameter for Windows Sleep() function is in milliseconds.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 12-12-2013, 03:44 AM
  2. Is it possible to call a function during execution?
    By workisnotfun in forum C Programming
    Replies: 1
    Last Post: 02-17-2013, 12:54 AM
  3. System pause
    By Ghezzo in forum C Programming
    Replies: 2
    Last Post: 09-28-2009, 06:26 AM
  4. is system("PAUSE") required in every program?
    By xstarburstbaby in forum C++ Programming
    Replies: 21
    Last Post: 09-03-2008, 05:18 AM
  5. system pause
    By Klinerr1 in forum C++ Programming
    Replies: 17
    Last Post: 07-17-2002, 10:30 PM