[SDL] Reading a line of text

Dino dinofizz at iafrica.com
Fri Sep 22 05:29:44 PDT 2006


Hello

I'm trying to use SDL with C++ to make a GUI for a college project. I'm trying
to read in a line of text using SDL, and then outputting it afterwards. I
understand how to read individual keyboard events, and am able to store the
letters pressed as chars. However when using the SDL_TTF library to output the
text it requires a char* as an argument. I am unsure how to consecutively append
the chars such that at the end i am able to send a char* to be outputted. I cant
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 = event2.key.keysym.sym;

				if (keyPressed == SDLK_ESCAPE)
			   		typing = false;
				else
				{
					key = char(keyPressed);
					//want to do something like:
                                        //output_line = output_line + key;
                                        //to add consecutive keyboard inputs   
                                    
				}
				
			}
		}
	}

        drawText(output_line);
}





More information about the SDL mailing list