Does anyone know an easy way to convert byte-counted strings to null-terminated strings I'm trying to pass a filename as an argument in a custom made worksheet function defined in an xll created in C++ 2005 express. I think the problem I'm encountering is that excel is passing a byte-counted string and the function in C++ needs a null-terminated string. So it comes down to finding an easy way to convert byte counted to null-terminated in my C++ code. Any ideas are appreciated. Thanks.

Converting byte counted strings to null-terminated strings
Timbo
It would help with an example. Do you get "5brian" for instance
I'm assuming that you can rely on the first real character being a non-digit. e.g. we won't try to encode "5" as "15".
Case 1: you're getting null terminated strings ("5brian\0") (Check for this: this is still a possibility; the length header is just an optimizaton.)
char* pos = thestring;
while( isdigit( *pos ) ) // walk past the digits
{
pos++;
}
char* newstring = strdup( pos ); // later, free this.
Case 2: no null terminated string (i.e. the value of the character after the n in "5brian" is undefined.)
int len = atoi( thestring );
assert( len >= 0); // negative values disallowed
char* newstring = (char*)malloc( len * sizeof(char) + 1); // later, free this
if( len > 0 )
{
while( isdigit( *pos ) ) // walk past the digits
{
pos++;
}
strcpy( newstring, pos, len ); // copy over the number of characters specified
}
newstring[len] = '\0'; // add null-terminator
Brian
iping
One approach is to first extract the byte count, then traverve to the first element in the string.
Kuphryn
Paul_P