strncpy.c

来自「Many C samples. It is a good sample for 」· C语言 代码 · 共 29 行

C
29
字号
/*  File   : strncpy.c
    Author : Richard A. O'Keefe.
    Updated: 20 April 1984
    Defines: strncpy()

    strncpy(dst, src, n) copies up to n characters of src  to  dst.   It
    will  pad  dst  on the right with NUL or truncate it as necessary to
    ensure that n characters exactly are transferred.   It  returns  the
    old value of dst as strcpy does.
*/

#include "strings.h"

char *strncpy(dst, src, n)
    register char *dst, *src;
    register int n;
    {
	char *save;

	for (save = dst;  --n >= 0; ) {
	    if (!(*dst++ = *src++)) {
		while (--n >= 0) *dst++ = NUL;
		return save;
	    }
	}
	return save;
    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?