3 ms·
I’m sure you meant something more along the lines of “strncpy is better than strcpy”.
by pshc 4y ago
I’m sure you meant something more along the lines of “strncpy is better than strcpy”.
- gregoryc_ 4y agomemcpy is better than strncpy and strcpy ;)
- naniwaduni 4y agoNah, strncpy is pretty bad and doesn't do something anyone really expects to want. (strncpy doesn't 0-terminate when it hit max length, nor stop when it sees its first 0 in the source buffer; it acts almost entirely like memcpy except that it writes zeroes to the full length of the destination upon seeing a zero in the source. This is allegedly useful for populating fixed-sized buffers in historical Unix, and can plausibly be useful for writing out tar headers, but in practice very little code in the wild does anything observably different if you #define strncpy memcpy.)