Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hold the console open in C?

Tags:

c

console

What is a 'nice' standard way of holding the console open in C? I'm looking for something similar to cin.clear(), cin.get(); in C++.

like image 759
Paul Manta Avatar asked Dec 28 '22 12:12

Paul Manta


2 Answers

puts("Press <enter> to quit:");
getchar();

That's assuming you need to do this in the program, which is probably not a good idea in general. And if I run your program from a shell, I'm going to be a bit annoyed at the extra step when I'm expecting the program to terminate nicely and let me have my next prompt.

like image 59
Keith Thompson Avatar answered Jan 11 '23 10:01

Keith Thompson


I use the below 2 lines of code.

printf("Press ENTER key to Continue\n");
getchar();
like image 43
Iphiclus Avatar answered Jan 11 '23 10:01

Iphiclus