Advertisement

Manipulating Strings

Started by May 10, 2001 11:32 PM
0 comments, last by Forcas 23 years, 9 months ago
I''m making an RPG-style text-box function using C++/W32API/DirectX, and I''m having trouble formatting the text. With MFC, it was easy. ALl I had to do to scrape some text off the left was to type MyString.GetLeft(n). Anyways, I''ve been trying to do this manually, but it isn''t quite working. Here''s my code:

void TextBox(int x1, int y1, char *texto)
{
	FillRect(x1, y1, x1 + 500, y1 + 200, COLOR(200, 64, 46));
	FillRect(x1 + 3, y1 + 3, x1 + 497, y1 + 197, COLOR(6, 7, 8));

	char *LineOne = "";
	char *LineTwo = "";
	int i;
	for(i = 0; i < 48; i++)
	{
		if(texto)
			LineOne += texto;
		else
			i=49;
	}

	if(texto[49])
	{
		for(i = 49; i < 98; i++)
		{
			if(texto)
				LineTwo += texto;
		}
	}


	Text(x1 + 3, y1 + 3, LineOne, RGB(128, 250, 64), 10, 10);
}
 </pre> 

When I call the function, I usually just get a bunch of mumbo-jumbo about blocks inside my textbox.

Please help.  </i>   

-Forcas
<HR>
<I>"Elvis is alive. He is Barney the purple dinosaur. He is the pied piper that leads our children into the wages of sin and eternal damnation."
<BR><BR>
<CENTER><IMG SRC="http://www.wsu.edu:8000/~lobo/gore/karate.gif">

    
-Forcaswriteln("Does this actually work?");
A char* is just that : a pointer to a char. If you use += on it, you simply place this pointer to a bad memory location. I don''t know so much about C string manipulation, so I will suggest the C++ way, which is simpler : (you need to include < string >)
  void TextBox(int x1, int y1, char *texto){  FillRect(x1, y1, x1 + 500, y1 + 200, COLOR(200, 64, 46));  FillRect(x1 + 3, y1 + 3, x1 + 497, y1 + 197, COLOR(6, 7, 8));  std::string Text = texto;  std::string LineOne(Text, 0, 48);  std::string LineTwo(Text, 49, 98);  Text(x1 + 3, y1 + 3, LineOne.c_str(), RGB(128, 250, 64), 10, 10);}  

This topic is closed to new replies.

Advertisement