| From: | Alexander Niven-Jenkins |
| Date: | 13 Sep 2000 at 18:28:53 |
| Subject: | Re: Initialising char... |
Hiya RODERICK (A-Scotland,ex1),
On 13-Sep-00, you wrote:
>> Regarding the other suggestion of initializing the array with "{ 0 }"
>> then this does have the effect of clearing the entire array in some
>> compilers, but AFAIK not defined that way in the standard, so
>> conforming compilers will only make the first array member contain a
>> zero.
> So what you are saying is that in some non-standard compilers the array
> will be initialised to all NULLs - but that in standard ones, only
> the first character is a NULL?
> If the first character is a NULL then the last character in the string
> is NULL (it's an empty string).... so isn't that exactly what Alexander
> wants...?
Hmmm. I will go into a bit more detail. I don't want an empty string I
want an array of char where the last character (although others can be) are
NULL initially.
Reason?
I have a buffer and I want to copy some data using memcpy into the
'string' of course because I'm not using any string related functions no
termination is done etc.
However the 'string' is then passed into some routines which expect it to
be null terminated.
See?
At the moment I am physically setting:
blah[sizeof(blah)-1] = '\0';
like Gunther suggested however I just wondered if there was a way to do
this on initialisation as the character array is fixed size.
Kind regards...
Alex