Re: char[] by danderson
danderson
Tue Jul 29 14:53:31 CDT 2003
"Kobi Ben Tzvi" <tsumbush@hotmail.comREMOVETHIS> wrote in message news:<utML5FeVDHA.1680@tk2msftngp13.phx.gbl>...
> Mark,
> > If I have a char[] buffer and I load some data in it by
> > using _read or something similar, and the buffer is bigger
> > than the data, how do I copy only the valid data to
>
> Declare variable called nDataSize which will hold the size of data that has
> been read, and when copying data for example with memcpy you will pass it as
> a parameter.
>
> > another buffer or trim the buffer?
> You can't trim buffer that was allocated on stack. You can allocate data
> dynamically with "malloc" and then 'trim' it using "realloc". But usually
> you should know the needed size before allocating, and allocate only needed
> size with new/malloc.
> --
> Regards,
> Kobi Ben Tzvi
>
>
> "Mark" <caveno@cs.com> wrote in message
> news:095401c355d4$09b747e0$a601280a@phx.gbl...
> > If I have a char[] buffer and I load some data in it by
> > using _read or something similar, and the buffer is bigger
> > than the data, how do I copy only the valid data to
> > another buffer or trim the buffer?
> > Thanks
Even better, if you are doing C++, do not use char[]/malloc/realloc,
uses vector<char>
Danderson