From: "A. Sinan Unur" Newsgroups: comp.os.msdos.djgpp Subject: Re: getkey() Date: 19 Oct 2001 16:36:08 GMT Organization: Cornell University Lines: 79 Sender: asu1 AT cornell DOT invalid (on 128.253.251.163) Message-ID: References: <9qpj2s$96v$1 AT cyan DOT nl DOT gxn DOT net> NNTP-Posting-Host: 128.253.251.163 X-Trace: news01.cit.cornell.edu 1003509368 8494 128.253.251.163 (19 Oct 2001 16:36:08 GMT) X-Complaints-To: usenet AT news01 DOT cit DOT cornell DOT edu NNTP-Posting-Date: 19 Oct 2001 16:36:08 GMT User-Agent: Xnews/4.06.22 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com "Bart van den Burg" wrote in news:9qpj2s$96v$1 AT cyan DOT nl DOT gxn DOT net: > I've got a problem with this function: you have a few. > -------------------------------- > void playGame() { good idea to explicitly decalre playGame as a no-arg function by using: void playGame(void) > char x; > char y; see the docs: info libc alpha getkey. getkey returns an int. > x = getkey(); > char buffer[2]; > sprintf(buffer, "%d", char(x)); now, seriously, what does char(x) mean? what is regel? have you tried compiling this? here's what I get: C:\var>gcc -c key.c -Wall key.c: In function `playGame': key.c:10: parse error before `char' key.c:11: `buffer' undeclared (first use in this function) key.c:11: (Each undeclared identifier is reported only once key.c:11: for each function it appears in.) key.c:11: parse error before `char' key.c:12: warning: implicit declaration of function `regel' key.c:14: parse error before `char' it is a good idea to post code that compiles so others can test it. > when I press, for example, "1", it says "49" instead of "1". > How can I fix this without changing the contents of the regel() function? Where did regel come from? if you want to print the character that corresponds to a given integer, then you should tell sprintf that is what you want. > sprintf(buffer, "%d", char(x)); I still don't know what you mean by char(x), but the format character should be %c, not %d. When dealing with computers, it helps to remember that the computer does exactly what you ask it. #include #include #include void playGame(void) { int x; x = getkey(); printf("Key pressed: %c\n", x & 0xff); return; } int main(void) { playGame(); return 0; } -- -------------------------------- A. Sinan Unur http://www.unur.com/