ssylee said:
If I'm being supplied with a char* that is not null-terminated,
A char * is a pointer to a single character. Presumably you mean that the
char * points to the first character in an arbitrarily long sequence, a
sequence which ought to have a null terminator but, for one reason or
another, has not. My answer is based on that understanding.
is it
impossible to transform it into a null terminated char* with only
abstract information about the char* information?
If you know where the null terminator is supposed to go, you can put one
there. s[n] = '\0';
If you don't, you can't, because a non-null-terminated sequence of chars
will not of itself provide you with that information (in the general
case). I am ignoring clever-clever answers such as:
char arr[55] = "The terminator belongs in place of this trailing colon:";
char *p = arr;
for what I hope are obvious reasons.
So no, you can't hope for the language to tell you where your data ends -
it's your job to know that.
--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999