实现myStrncpy的功能,代码如下。
/********************************************************************
created: 2012/09/06
created: 6:9:2012 23:56
filename: E:\C\myStrncpy\myStrncpy.c
file path: E:\C\myStrncpy
file base: myStrncpy
file ext: c
author:
purpose:
*********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char *myStrncpy( char *dst, const char *src, int num );
int main()
{
char str[] = "characters has copied!";
char dst[128] = " ";
int num = 60;
myStrncpy( dst, str, num );
return 0;
}
char *myStrncpy( char *dst, const char *src, int num )
{
char *adress = dst;
while ( num-- != 0 )
{
while ( ( *dst++ = *src++ ) != '\0' )
;
}
return adress;
}