strncpy

brnstnd at stealth.acf.nyu.edu brnstnd at stealth.acf.nyu.edu
Wed Jan 24 05:22:39 AEST 1990


In article <ZC91DJ4xds13 at ficc.uu.net> peter at ficc.uu.net (Peter da Silva) writes:
> > That's why it is a bastard function - it is designed to work with
> > the null-termination convention but does not guarantee closure.
> What it does is provide the most generally useful facility.

No.

> If it always
> null-terminated, it couldn't be used for copies into a known fix-sized
> buffer.

Huh? strncpy(s1,s2,n) should work like the current strncpy(s1,s2,n)
followed by s1[n - 1] = '\0' if necessary. That's a copy into a known
fixed-size buffer, preserving null termination.

> And since you know the length, you can always null-terminate
> the string yourself.

Since I do, in fact, always null-terminate the string myself, I'd prefer
that strncpy do the job for me.

---Dan



More information about the Comp.lang.c mailing list