2

How can I sleep or pause the program excecution by a few seconds in C? I'm looking for something like this that is used in Java:

Thread.sleep(interval); 

Is possible do this using C ? Thanks in advance.

user
  • 2,015
  • 6
  • 22
  • 39
hcarrasko
  • 2,320
  • 6
  • 33
  • 45
  • 3
    There is not really any suitable standard C function. You should use system-specific functions for this. In which case you have to tell us which system you are programming for. – Lundin Oct 20 '15 at 12:01
  • Yeah - call your OS Sleep() API, whatever that is:) – Martin James Oct 20 '15 at 12:28

2 Answers2

6
#include <stdio.h>
#include <unistd.h>

int main (void){

    sleep(3);

    return 0;
}

Read more here.

4

There is an answer here: What is the proper #include for the function 'sleep' in C?

Be careful that it works differently in Unix and Windows, whereas in one is measured in millisecs and in the other in secs.

user
  • 2,015
  • 6
  • 22
  • 39