926 Subj : choiceyn: cut down choice command, use of sleep, kbhit and getch To : borland.public.cpp.borlandcpp From : "frank spencer" Date : Mon Jan 12 2004 05:16 pm Hello, I have put this short program together and would like constructive comments on what improvements could be made. It works like the choice.com command on win98 with no parameters. I am particularly concerned about the use of sleep, kbhit and getch but any other errors found would be appreciated. It seems to work but I'm guessing there are some naive assumptions in there. Thanks in advance for any help given Hal /*__________________________________________________________________________ _*/ /*__________________________________________________________________________ _*/ /* * choiceyn.c - emulates Win98's choice.com (with no parameters) * no warranty whatsoever given or implied. * * Hal Styli, 2004. */ #include #ifdef _MSC_VER #include #include #define KBHIT() _kbhit() #define GETCH() _getch() #define SLEEPX(s) Sleep((s)*1000) #elif defined( __BORLANDC__ ) #include #define KBHIT() kbhit() #define GETCH() getch() #define SLEEPX(s) _sleep(s) #else #pragma message( "\n\n* * * U n t e s t e d * * *" ) #pragma message( "This source has not been tested on this platform/with this compiler" ) #include "*** ERROR -- Untested environment ***\n\n" #endif #define BEEP '\a' /*__________________________________________________________________________ _*/ /*__________________________________________________________________________ _*/ int main() { char c; putchar('['); putchar('Y'); putchar(','); putchar('N'); putchar(']'); putchar('?'); for(;;) { if (KBHIT()) { c=GETCH(); if( (c=='Y') || (c=='y') ) { putchar('Y'); putchar('\n'); return 1; } else if ( (c=='N') || (c=='n') ) { putchar('N'); putchar('\n'); return 2; } else putchar(BEEP); } else SLEEPX(1); } } /*__________________________________________________________________________ _*/ /*__________________________________________________________________________ _*/ . 0