[SDL] Reading a line of text
lilith at dcccd.edu
Fri Sep 22 09:52:22 PDT 2006
Some of it may depend on what you're using to hold the input string. If
you're using a char buffer like
char input ;
you probably need to access it on a character by character basis using
an index, say 'i', into the array
input [i] = input_char;
i++; // increment the index
input[i++] = input_char;
or by using an incrementing pointer.
char *p = input;
on each input character you woudl do
*(p++) = input_char;
But you have to be careful about what's input and how much. You don't
want to exceed the size of your buffer and you'll need to account for
backspaces and dels and then be sure not to underrun your buffer.
You might also use std::string, which doesn't present the need for size
checking. But off hand I don't know if it handles backspaces and such.
>>> On 9/22/2006 at 7:29 AM, in message
<loom.20060922T141951-997 at post.gmane.org>,
Dino <dinofizz at iafrica.com> wrote:
> I'm trying to use SDL with C++ to make a GUI for a college project.
> to read in a line of text using SDL, and then outputting it
> understand how to read individual keyboard events, and am able to
> letters pressed as chars. However when using the SDL_TTF library to
> text it requires a char* as an argument. I am unsure how to
> the chars such that at the end i am able to send a char* to be
> cast the char to the char* even when passing its address.
> Example code shown:
> void getText ()
> SDL_Event event;
> bool typing = true;
> char* output_line = ""
> char key = ' ';
> while (typing)
> if (SDL_PollEvent(&event))
> if (event.type == SDL_KEYDOWN)
> SDLKey keyPressed =
> if (keyPressed == SDLK_ESCAPE)
> typing = false;
> key = char(keyPressed);
> //want to do something like:
> //output_line = output_line +
> //to add consecutive keyboard
> SDL mailing list
> SDL at libsdl.org
More information about the SDL