Mail Archives: djgpp/2001/10/19/12:49:35
"Bart van den Burg" <bart AT bart99 DOT tmfweb DOT nl> 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 <stdio.h>
#include <pc.h>
#include <keys.h>
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/
- Raw text -