Re: set char to empty

From: Martin Ambuhl (mambuhl_at_earthlink.net)
Date: 08/02/04


Date: Mon, 02 Aug 2004 05:22:04 -0400

Magix wrote:

> "Martin Ambuhl" <mambuhl@earthlink.net> wrote in message
> news:2n60itFsaj2rU1@uni-berlin.de...
>
>>Magix wrote:
>>
>>
>>>Hi,
>>>
>>>How do I set the char [ ] to empty ?
>>>
>>>let say I have,
>>>char test[20];
>>
>> char test[20] = "";
>>if you want to initialize it to an empty string.
>>
>>
>>>can I do like this :
>>>*test = NULL;
>>
>> *test (or test[0]) is a char.
>> NULL is a pointer.
>> Thou shalt not assign pointer values to chars.
>>
>> *test = 0;
>> test[0] = 0;
>>
>>or any of several synonymous statements will do.
>>
>
>
> I used test as string buffer. After strcat to test buffer in this process, i
> will need to clear the buffer,

No, you don't. You just need to mark it with an immediate end-of-string
'\0'.

> and strcat another info to test buffer in
> another process.

For which my above suggestions will work just fine.



Relevant Pages

  • Re: Question on
    ... If you terminate the above statement with a semicolon, then it initialises the pointer s to be a null pointer. ... Note that it does not initialise s to point to an empty string. ... You have to specify a size for the buffer. ...
    (comp.lang.c)
  • Re: set char to empty
    ... > if you want to initialize it to an empty string. ... > Thou shalt not assign pointer values to chars. ... After strcat to test buffer in this process, ...
    (comp.lang.c)
  • [net-next PATCH 4/5] igb: Add support for enabling VFs to PF driver.
    ... pointer to the hardware struct ... under the terms and conditions of the GNU General Public License, ... * @msg: The message buffer ... * returns SUCCESS if it successfully copied message into the buffer ...
    (Linux-Kernel)
  • Re: When to stop - how do I work out when to stop processing
    ... I know the length of the entire byte stream. ... //parse buffer received into tlv messages ... However, if doing direct pointer manipulation is still desired, ... with 'process_tlvs' being an array of pointer-to-function. ...
    (comp.lang.c)
  • Re: some unanswered questions on C
    ... A pointer variable that's never been given a value. ... you don't know what memory you're modifying. ... >what i want to ask is that when i declare my buffer for fgets as ... "char *buffer" creates a pointer, ...
    (comp.unix.programmer)