/ Published in: C
Expand |
Embed | Plain Text
/* * Copy src to dst, truncating or null-padding to always copy n bytes. * Return dst. * This routine completes in a single loop but runs slower than libc * because 'write_nul' is evaluated for every char. * Ansi string only! */ char* _strncpy(char* dst, const char* src, int n) { char* d = dst; const char* s = src; int write_nul = 0; while (n-- > 0) { *d++ = write_nul ? 0 : *s; if (!write_nul) { write_nul = (*s == 0); } s++; } return dst; } int main() { char dst[10]; }
You need to login to post a comment.
