delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/10/16/18:19:10

From: "Ingo Ruhnke" <ruhnke AT owl-online DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: problem with readkey()
Date: 16 Oct 1997 19:21:35 GMT
Organization: Telemedia News Server
Lines: 45
Message-ID: <01bcda6c$d9e94d80$0200a8c0@ingo>
NNTP-Posting-Host: gtso-m71-239.pool.mediaways.net
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

I got here some simple code which dosen't run as I expect it to work:

#include <stdio.h>
#include <allegro.h>

void main()
{
 allegro_init();
 install_keyboard();

 if (readkey() == 'a') {
   printf ("a was pressed");
 } else {
   printf ("a wasn't pressed");
 }
}

this didn't get me the info about that was pressed, it said every time "a
wasn't pressed", but if i modify it to this:

void main()
{
 char c;
/* ^^^^^^ */
 allegro_init();
 install_keyboard();

 if ((c = readkey()) == 'a') {
/*  ^^^^  */
   printf ("a was pressed");
 } else {
   printf ("a wasn't pressed");
 }
}

the programm works fine. Can anybody tell me why this is so. And if i use
getchar() instead of readkey() it also works like expected, so were is the
problem which this code.

Thanks
Ingo
-- 
Ingo Ruhnke
ruhnke AT owl-online DOT de
http://www.geocities/SiliconValley/Horizon/2159

- Raw text -


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