1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <string.h> // for strncpy, size_t char *strncpy(char *restrict s1, const char *restrict s2, size_t n) { char *result = s1; while (n > 0 && *s2 != '\0') { *s1++ = *s2++; n--; } if (n > 0) *s1 = '\0'; return result; }