Home >Backend Development >C#.Net Tutorial >How to pause the execution of C language program

How to pause the execution of C language program

下次还敢
下次还敢Original
2024-04-05 00:15:191252browse

How to pause the execution of a C language program

In C language programming, you can pause the execution of the program by using the following function:

  • sleep()

sleep() The function will pause the program for the specified number of seconds. Its prototype is:

<code class="c">#include <unistd.h>
unsigned int sleep(unsigned int seconds);</code>

where, The seconds parameter specifies the number of seconds to pause. After the function call is successful, the program will pause execution and wait for the specified time.

Steps to pause the program:

  1. Include the necessary header files in the header file: <unistd.h>
  2. Use the sleep() function to pause program execution.
  3. Specify the number of seconds to pause as a parameter.

Example:

<code class="c">#include <stdio.h>
#include <unistd.h>

int main() {
    printf("这个程序将会暂停 5 秒。\n");
    sleep(5);
    printf("程序已恢复执行。\n");

    return 0;
}</code>

Output:

<code>这个程序将会暂停 5 秒。
(5 秒暂停)
程序已恢复执行。</code>

The above is the detailed content of How to pause the execution of C language program. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn