delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/09/18/10:52:21

From: "marcus" <marcus34 AT www DOT multimania DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Getche doesnt work!
Date: Wed, 18 Sep 2002 14:38:01 +0200
Organization: Wanadoo, l'internet avec France Telecom
Lines: 195
Message-ID: <am9s1m$79i$1@wanadoo.fr>
References: <am7jh7$ru1$1$8300dec7 AT news DOT demon DOT co DOT uk>
NNTP-Posting-Host: aputeaux-102-1-5-91.abo.wanadoo.fr
X-Trace: wanadoo.fr 1032352630 7474 80.14.191.91 (18 Sep 2002 12:37:10 GMT)
X-Complaints-To: abuse AT wanadoo DOT fr
NNTP-Posting-Date: 18 Sep 2002 12:37:10 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

getche() returns a character .
But a character can be an Xtend character, such like "PageUp, F1, F2 ....
and so on".
In that case, instead of returning the char code itself, it returns first
"0" then the charcode.
In the case u r not waiting for Xtend or such chars, u'd better use a short
selffunction instead of getche(), like :

if(getche()==0) getche();    // that's just an example

or :

myfunc(){
 if(getche()==0) getche();
 else {
//ur code here. u sure the char isn't an xtend one
 }
}

Jenny Reeves <jenny DOT reeves AT s-4-b DOT com> a écrit dans le message :
am7jh7$ru1$1$8300dec7 AT news DOT demon DOT co DOT uk...
> Getche doesnt work!
>
> Hello,
>
> I was hoping someone could help me with my program, everything is working
> fine apart from getche function in one of my functions (apologies if my
> terminology is wrong).  Its a basic cash machine program that goes to a
> welcome screen then takes and verifies the users account and PIN number
> before taking them to the main menu: the user can then select between 1-5
(5
> being quit whole program). The problem is the user has to press any key
> twice when entering their choice, if they press enter once it just goes to
> the next line, and doesn't accept the choice until you've pressed it
twice?
> main code for the program is -
> void main() /*Main program will define the order in which the the
functions
> run*/
> {
>
>
>
>       AccFile = fopen(FileName      ,"r+");/*Opens the Accounts.dat file
to
> AccFile (temporary space in RAM)*/
>
>       fill_array();  /*reads account.dat file into struct accounts*/
>
>
>
>       do/*This is a Do While Loop, it will run this part of the program
> until the variable Choice is equal to 5 which in the main menu is "Quit"*/
>
>       {
>
>             welcome();
>
>             get_acc_no();
>
>             get_pin();
>
>
>
>             if (match == 'Y') /*This is an IF statement if the variable
> "match" = Y   then do this*/
>
>                            /*If not start again with welcome screen the
> match variable appears in the get_pin function*/
>
>                   {
>
>                   menu();
>
>                   get_choice();
>
>                   do_choice();
>
>                   }
>
>       }while (choice !=5);
>
>
>
>       rewind(AccFile);/*Rewinds file from las time it was Written*/
>
>
>
>       for (i=0;i<=9;i++)/*Do the Write File function 10 times, this
enables
> all ten accounts and any new info entered by the user in RAM to be written
> to permanent memory*/
>
>       write_file(AccFile,accounts[i]);
>
>
>
>       fclose(AccFile);/*Close the AccFile*/
>
> }
>
> The get choice fuction is -
>
>
>
>
>
> void get_choice()
>
> {
>
>  gotoxy(21,22);
>
>  printf("Please enter your choice: ");
>
>  scanf("%d",&choice);
>
>  getche();
>
>  }
>
> The function that follows is do choice -
>
>
>
> void do_choice()
>
> {
>
>   switch (choice) {
>
>
>
>   case 1:
>
>       balance();
>
>       break;
>
>   case 2:
>
>       withdraw();
>
>       break;
>
>   case 3:
>
>       deposit();
>
>       break;
>
>   case 4:
>
>       help();
>
>       break;
>
>   case 5:
>
>        clrscr();
>
>        gotoxy(21,11);
>
>        printf("EXITING CASHPOINT PROGRAM!......... ");
>
>        break;
>
>   case 6:
>
>       printf("\n ERROR you have selected an invalid option");
>
>        getche();
>
>        break;
>
>       }
>
>
>
> }
>
>
> Any help, greatly appreciated
>
>
> Chrs,
>
> Jenny
>
>
>
>
>


- Raw text -


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