[C] Trouble appending last character of a string to a new string :/

Started by
1 comment, last by yewbie 15 years, 8 months ago
Maybe I'm just tried but I cannot seem to figure out what I am doing wrong here :/ What I am doing is taking a string and slicing off 1 character at a time until enough has been cut off to fit in my space then copying everything that I sliced off to a new string and here is how im doing it maybe someone can see something I missed (I'm not all that great of a programmer so it could just be something I don't know!)

while(TextSize > 200)//if our text size if greater than 600
	{
		char test[1]= {'\0'};//our character zeroed for easy memcpy
		size_t StringLength =0;//this holds the size of our string
		StringLength = strlen(NewString);//get our string length

		TextSize = GetSizeForString(NewString);//get the text size we would output in pixels
		
		test[1] = NewString[StringLength-1]; //copy that string
		
		NewString[StringLength-1] = '\0'; //make it blank now
		strncat(Line2, test, 1);
		MoreLines = true;
	}
the GetSizeForString function just returns the pixel size of the string to be output NewString is our unmodified String Line2 is supposed to be the string all the extra characters are being output to.. [Edited by - yewbie on August 17, 2008 3:42:02 PM]
Advertisement
Heh sorry for the post I fixed it :/
it needed to be
test[0] = NewString[StringLength-1]; //copy that string
I was just copying the wrong part!
Ok well its working, but the line

strncat(Line2, test, 1);

copies the text backwards to the next string

like "Test This Out"
becomes "tuO sihT tseT"

is there any function like strcat that appends to the front of a string?

This topic is closed to new replies.

Advertisement