6 ms·
Depends on the functions used. memcpy is better than strcpy
by gregoryc_ 4y ago
Depends on the functions used. memcpy is better than strcpy
- pshc 4y agoI’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.)