C:按键终止程序

And*_*ech 5 c

在C中,我通常使用getch()函数来等待按下一个键然后结束程序,但是最近我读到了,因为它不是标准函数,所以使用它是不好的编程习惯.

因此,而不是以下:

int main() {
    dosomething();
    getch(); //wait for the user to see the results and press a key to end
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能更换getch

ale*_*xkr 8

getc(stdin); 在这个意义上是便携式的