Article View: microsoft.public.vc.language
Article #6choiceyn: cut down choice command, use of sleep, kbhit and getch
From: frank spencer
Date: Mon, 12 Jan 2004 17:09
Date: Mon, 12 Jan 2004 17:09
92 lines
3700 bytes
3700 bytes
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 <stdio.h>
#ifdef _MSC_VER
#include <conio.h>
#include <windows.h>
#define KBHIT() _kbhit()
#define GETCH() _getch()
#define SLEEPX(s) Sleep((s)*1000)
#elif defined( __BORLANDC__ )
#include <conio.h>
#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);
}
}
/*__________________________________________________________________________
_*/
/*__________________________________________________________________________
_*/
Technical Details
Message-ID:
<4002d4eb_5@127.0.0.1>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newshosting.com!nx02.iad01.newshosting.com!38.119.100.112.MISMATCH!news-out2.nuthinbutnews.com!local!corp-news!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f8d38,6ae23aa1a5869fb6,start X-Google-Attributes: gidf8d38,public X-Google-Thread: f7a51,6ae23aa1a5869fb6,start X-Google-Attributes: gidf7a51,public X-Google-ArrivalTime: 2004-01-12 09:10:19 PST From: "frank spencer" <no_spam@all> Newsgroups: microsoft.public.vc.language,borland.public.cpp.language Subject: choiceyn: cut down choice command, use of sleep, kbhit and getch Date: Mon, 12 Jan 2004 17:09:56 -0000 Lines: 96 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2727.1300 Message-ID: <4002d4eb_5@127.0.0.1> X-Comments: This message was posted through Newsfeed.com X-Comments2: IMPORTANT: Newsfeeds.com does not condone, nor support, spam or any illegal or copyrighted postings. X-Comments3: IMPORTANT: Under NO circumstances will postings containing illegal or copyrighted material through this service be tolerated!! X-Report: Please report illegal or inappropriate use to <abuse@newsfeed.com> You may also use our online abuse reporting from: http://www.newsfeed.com/abuseform.htm X-Abuse-Info: Please be sure to forward a copy of ALL headers, INCLUDING the body (DO NOT SEND ATTACHMENTS) Organization: Newsfeed.com http://www.newsfeed.com 100,000+ UNCENSORED Newsgroups. Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newshosting.com!nx02.iad01.newshosting.com!38.119.100.112.MISMATCH!news-out2.nuthinbutnews.com!local!corp-news!not-for-mail