C++程序  |  24行  |  256 B

/*
 * stpncpy.c
 *
 * stpncpy()
 */

#include <string.h>

char *stpncpy(char *dst, const char *src, size_t n)
{
    char *q = dst;
    const char *p = src;
    char ch;

    while (n--) {
	*q = ch = *p++;
	if (!ch)
	    break;
	q++;
    }

    return q;
}