Velocity Reviews > transforming from a non-null terminated string into a null terminatedstring

# transforming from a non-null terminated string into a null terminatedstring

ssylee
Guest
Posts: n/a

 08-12-2008
If I'm being supplied with a char* that is not null-terminated, is it
impossible to transform it into a null terminated char* with only
abstract information about the char* information?

santosh
Guest
Posts: n/a

 08-12-2008
ssylee wrote:

> If I'm being supplied with a char* that is not null-terminated, is it
> impossible to transform it into a null terminated char* with only
> abstract information about the char* information?

It depends. One piece of information that you *must* know is *where* to
place the null character, i.e., you must know the length of the char
array that your char* points at. Otherwise you'll either truncate your
array or write beyond it's bounds.

What abstract information have you been given about the char*?

ssylee
Guest
Posts: n/a

 08-12-2008
On Aug 12, 12:15*pm, santosh <(E-Mail Removed)> wrote:
> ssylee wrote:
> > If I'm being supplied with a char* that is not null-terminated, is it
> > impossible to transform it into a null terminated char* with only
> > abstract information about the char* information?

>
> It depends. One piece of information that you *must* know is *where* to
> place the null character, i.e., you must know the length of the char
> array that your char* points at. Otherwise you'll either truncate your
> array or write beyond it's bounds.
>
> What abstract information have you been given about the char*?

Thank you for your replies. I found out that there is an information
that I have missed out in terms of the ASCII to UNICODE conversions.
So I guess this problem is solved.

Martin Ambuhl
Guest
Posts: n/a

 08-12-2008
ssylee wrote:
> If I'm being supplied with a char* that is not null-terminated, is it
> impossible to transform it into a null terminated char* with only
> abstract information about the char* information?

It depends on what that "abstract information" is. If it includes the
length of the information you want in the string, or if it indicates
that the 1st (or 2nd or some other specific ordinal) occurrence of a
certain character is the end of the wanted resultant string, obviously
it is trivial. Otherwise, it is near impossible.

CBFalconer
Guest
Posts: n/a

 08-12-2008
ssylee wrote:
>
> If I'm being supplied with a char* that is not null-terminated,
> is it impossible to transform it into a null terminated char*
> with only abstract information about the char* information?

What specifies the length of the string you have stored in there?

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>