This is the mail archive of the
glibc-linux@ricardo.ecn.wfu.edu
mailing list for the glibc project.
Re: problem with malloc?
- To: glibc-linux at ricardo dot ecn dot wfu dot edu
- Subject: Re: problem with malloc?
- From: Kervin <kpierre at winnie dot fit dot edu>
- Date: Sun, 23 Apr 2000 16:48:53 -0400 (EDT)
- cc: Kaz Kylheku <kaz at ashi dot footprints dot net>
- Reply-To: glibc-linux at ricardo dot ecn dot wfu dot edu
> target = ( char * )malloc( (len+1)*sizeof( char ) );
> strncpy( target, buffer, len );
target = strdup(buffer);
or...
target = ( char * )malloc( (len+1)*sizeof( char ) );
memset(target, '\0',len+1);
strcpy( target, buffer);
when not sure, memset! : )
goes double if string's buffer is being reused.
____________________________________________________________
Kervin Pierre
"My grandfather once told me there are two kinds of people:
those who do the work and those who take the credit. He told
me to try to be in the first group -- there is less competition
there."
-- Indira Gandhi