This is the mail archive of the glibc-linux@ricardo.ecn.wfu.edu mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: problem with malloc?



> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]