delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/02/17/06:34:30

From: gripinc AT hotmail DOT com (Neither)
Newsgroups: comp.os.msdos.djgpp
Subject: catching irregular keys
Date: Mon, 16 Feb 1998 22:16:26 GMT
Organization: The Evil Within
Lines: 32
Message-ID: <34e8b9c6.16571480@n5.supernews.com>
Reply-To: gripinc AT hotmail DOT com
NNTP-Posting-Host: 15517 AT 208 DOT 0 DOT 232 DOT 186
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In this bit of code, the user can type as long as he wants until
he/she types the '9' key. How can I make the program terminate on an
'alt-x' or 'F10', or anything besides a "regualr key". Thanks in
advance to anyone who can help me. 

Here's the code:

#include <fstream.h>
#include <stdio.h>
#include <conio.h>
main()
{

//Declarations--
char avar,filename[12],phrase;
int count;
fstream ptr;
//---------------

clrscr();

cout << "Filename? ";
gets(filename);
cout << "\nWhat information do you want in " << filename << " ?\n";

ptr.open(filename, ios::out);
while ((phrase = getche()) != '9')
{
 ptr << phrase;
}
 ptr.close();

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019