NO

Author Topic: How to have a "hit any key" pause  (Read 6168 times)

jwzumwalt

  • Guest
How to have a "hit any key" pause
« 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;
}
« Last Edit: April 26, 2009, 03:20:52 AM by jwzumwalt »

Offline Stefan Pendl

  • Global Moderator
  • Member
  • *****
  • Posts: 582
    • Homepage
Re: How to have a "hit any key" pause
« Reply #1 on: April 26, 2009, 09:08:35 AM »
You could use get() or something similar.
---
Stefan

Proud member of the UltraDefrag Development Team

cardoso.rafael

  • Guest
Re: How to have a "hit any key" pause
« Reply #2 on: May 04, 2009, 06:41:23 PM »
Why not system("pause")?

Rafael Cardoso

PauloH

  • Guest
Re: How to have a "hit any key" pause
« Reply #3 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.

rxantos

  • Guest
Re: How to have a "hit any key" pause
« Reply #4 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