Pelles C forum

C language => User contributions => Topic started by: jwzumwalt on April 26, 2009, 02:58:31 AM

Title: How to have a "hit any key" pause
Post by: jwzumwalt on April 26, 2009, 02:58:31 AM
/*
   --------------------------------------------------------------------
   PROGRAM:     hit-any-key.c       Ver: 1.0        Rev: 05/01/2009
   DESCRIPTION: C tutor
   BY:          Jan Zumwalt - www.neatinfo.com
   --------------------------------------------------------------------
   COMMENTS:    Your Very First C Program - Displaying Hello World
   --------------------------------------------------------------------
   Developed:
      Tested using the free C IDE & compiler "PellesC" v5.00.8

   Ver info:
      1.0 none
*/ 
#include <stdio.h>
#include <conio.h>

#define HIT_ANY_KEY printf("\n\t Hit any key to continue..."); while(1){ if( _kbhit()) { break; } }

void main()
{
printf("\n\t Hello world");

HIT_ANY_KEY;
}
Title: Re: How to have a "hit any key" pause
Post by: Stefan Pendl on April 26, 2009, 09:08:35 AM
You could use get() or something similar.
Title: Re: How to have a "hit any key" pause
Post by: cardoso.rafael on May 04, 2009, 06:41:23 PM
Why not system("pause")?

Rafael Cardoso
Title: Re: How to have a "hit any key" pause
Post by: PauloH on May 08, 2009, 12:26:52 AM
Quote
Why not system("pause")?

Because this is system dependent and is not portable c code. But if you want run your program only in windows environment that's ok.

Kind regards.
Title: Re: How to have a "hit any key" pause
Post by: rxantos on August 20, 2010, 07:58:03 PM
#define HIT_ANY_KEY printf("\n\t Hit any key to continue..."); while(1){ if( _kbhit()) { break; } }
This will hog the cpu while waiting for a keypress.
Try to sleep for 1 second between calls to _kbhit