

Ask HN: Preferred string copy function in C? - codehero

1. strcpy<p>2. strncpy<p>3. stpcpy<p>4. memcpy
======
cd34
Depending on your requirements, each has its benefits and drawbacks. Depending
on your architecture, there are versions that are faster than the libc
version.

None of the functions you have listed are true equivalents, so, your situation
will dictate which you need to use.

~~~
codehero
strcpy and stpcpy are functionally equivalent, but differ only in return
value. stpcpy is superior because it points to the end of the string, thus
letting the caller know how many bytes were copied.

------
steve-howard
strdup is nice, but it always depends on your use case.

memcpy is probably best if you're keeping track of lengths separately.

------
tlb
strlcpy

