Re: strncpy and 'n'
In article <lnboouef7m.fsf@nuthaus.mib.org>,
Keith Thompson <kst-u@mib.org> wrote:
>If it had been defined something like this:
>
> char *better_strncpy(char *dest, const char *src, size_t n) {
> dest[0] = '\0';
> return strncat(dest, src, n);
> }
>
>then it would be reasonable to call it a "safer" version of strcpy.
Well there you go. You pretty much solved your complaint. It you are
catenating several strings, it's almost more natural to zero out at the
beginning, then use 'strcat' from there.
You can understand why you might want to zero out the whole array at the
start; from there 'strcat' is fine.
|