getchar() 解决自动关闭终端

#include<stdio.h>

int  main()
{
        printf("helloworld !");
        getchar();   // 在return 之前加入getchar();可以防止程序一运行结束,就自动退出终端
        return 0;
}

在return 之前加入getchar();可以防止程序一运行结束,就自动退出终端。

该行读取一次键的按下,程序会在用户输入enter前暂停。

有时根据程序的需要,可能还需要一个击键等待。

这种情况下,必须用两次getchar();

getchar();

getchar();

原文地址:https://www.cnblogs.com/sdb1942/p/13210928.html