July 17th, 2002, 04:17 AM
copying a string
I would like to know how I would go about copying one string from another, with the added option of stating from where I want to copy.
I know that you can use the strncpy() function to specify how many chars you want to copy.
But I don't want to copy from the start of the string neccesarily. I might want to copy from char no 5.
Hope somebody can help
July 17th, 2002, 06:31 AM
In that case you'll still be using strncpy; instead of passing a pointer to the start of the source string, you'll pass a pointer to the fifth char in the string:
Watch out for overstepping boundaries though; that's nasty...
char *src, *dst;
strncpy (dst, src + 5, strlen(s) + 1 - 5;
"A poor programmer is he who blames his tools."
July 19th, 2002, 09:48 PM
for String objects you can use this:
theString.copy(str, x, n);
// Compares theString and str, starting
// at position x, and continuing for n