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

Discussion in 'C Programming' started by ssylee, Aug 12, 2008.

1. ### ssyleeGuest

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?

ssylee, Aug 12, 2008

2. ### santoshGuest

Re: transforming from a non-null terminated string into a null terminated string

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*?

santosh, Aug 12, 2008

3. ### ssyleeGuest

Re: transforming from a non-null terminated string into a nullterminated string

On Aug 12, 12:15 pm, santosh <> 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.

ssylee, Aug 12, 2008
4. ### Martin AmbuhlGuest

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.

Martin Ambuhl, Aug 12, 2008
5. ### CBFalconerGuest

Re: transforming from a non-null terminated string into a nullterminated string

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>