Sign in to follow this  
yewbie

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

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this