Mail Archives: djgpp/2001/10/19/12:34:32
Bart van den Burg <bart AT bart99 DOT tmfweb DOT nl> wrote:
> hi
> I've got a problem with this function:
> --------------------------------
> void playGame() {
> char x;
> char y;
> x = getkey();
> char buffer[2];
^^^^^^^^^^ This buffer is probably too short for what you're
trying to do. At the very least, you should limit the maximal output
width of your sprintf() format accordingly.
> sprintf(buffer, "%d", char(x));
You don't show what function "char" is.
And I'm quite sure you don't want the code number of the character you
input, as a decimal string, which is what this sprintf() call will give
you. What you want would be much easier to do like this:
buffer[0] = x;
buffer[1] = '\0';
This makes the string in "buffer" read "1", if you typed '1'.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -