• 14
• 12
• 9
• 10
• 13

# A trivial problem in C

This topic is 4740 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I know, I could have searched for this on Google, but I really need a quick solution instead of scanning through results (I'm that lazy). I am trying to write a console program which waits for the user to press a key after it's done executing, before it closes. Now, I know I can include conio.h and use the getch() function, but this does not work with Linux. How else can I possibly implement the "Press any key to continue..." feature? Thanks.

##### Share on other sites
dunno if linux has a pause command but if it does
system("pause");
would be an alternative system resides in stdlib.h

##### Share on other sites
Wait, why is conio unavailable in linux?

The conio stuff -came- from the unix world, didn't it?

##### Share on other sites
There is no pause command in Linux.

How about. . .
#include <iostream>void pause() {  using namespace std;  cout << "Press enter to continue.";  cout.flush();  cin.sync();  cin.get();  cin.sync(); }

##### Share on other sites
Sadly, I'm restricted to C. I cannot use any C++ code.
conio.h is not in the ANSI standard library so I suppose that's why it's not available.

##### Share on other sites
puts( "press any key d00d!");fflush( stdin);getchar();

should use only stdio.h

##### Share on other sites
Use getchar(); which is implemented in all C distributions.

#include <stdio.h>void pause(void) {  fputs("Press enter to continue.", stdout);  fflush(stdout);  while(getchar()!='\n'); }