Re: set char to empty

From: Darrell Grainger (darrell_at_NOMORESPAMcs.utoronto.ca.com)
Date: 08/02/04


Date: 2 Aug 2004 16:43:34 GMT

On Mon, 2 Aug 2004, Magix wrote:

> Hi,
>
> How do I set the char [ ] to empty ?

You need to define what 'empty' means to you.

> let say I have,
> char test[20];
>
> can I do like this :
> *test = NULL;

No. *test is actually the same as using test[0]. The NULL macro is not a
char. You could use:

        test[0] = '\0';
or
        *test = '\0';

Essentially, test is an array of twenty char. If you set the first char to
'\0' (null character), all the string functions will see this array as an
empty string. If you want to remove EVERYTHING from the string then you
need to fill all twenty elements with the null character. Something like:

        int i;

        for(i = 0; i < sizeof(test); i++)
                test[i] = '\0';

-- 
Send e-mail to: darrell at cs dot toronto dot edu
Don't send e-mail to vice.president@whitehouse.gov


Relevant Pages