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

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

  1. ssylee

    ssylee Guest

    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
    #1
    1. Advertising

  2. ssylee

    santosh Guest

    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
    #2
    1. Advertising

  3. ssylee

    ssylee Guest

    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
    #3
  4. 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
    #4
  5. ssylee

    CBFalconer Guest

    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>
    Try the download section.
     
    CBFalconer, Aug 12, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael
    Replies:
    21
    Views:
    1,368
    Robert Kern
    Sep 15, 2006
  2. Replies:
    0
    Views:
    477
  3. Raghavendra Mahuli

    Non Null Terminated string

    Raghavendra Mahuli, Sep 15, 2005, in forum: C++
    Replies:
    4
    Views:
    327
    Richard Herring
    Sep 15, 2005
  4. Replies:
    10
    Views:
    640
  5. Grey Alien

    Working with NON-NULL terminated strings

    Grey Alien, Jul 14, 2007, in forum: C Programming
    Replies:
    4
    Views:
    607
    santosh
    Jul 18, 2007
Loading...

Share This Page