c语言练习46:模拟实现strncpy

模拟实现strncpy

c语言练习46:模拟实现strncpy_第1张图片

 模拟实现:

#include
char* my_strncpy(char*dest,char*src,size_t num) {
	char* ret = dest;
	size_t i = 0;
	for (i = 0; i < num; i++) {
		*dest = *src;
		dest++;
		src++;
	}
	*dest = '\0';
	return ret;
}
int main() {
	char aim[50] = { 0 };
	char src[] = "abcdefg";
	my_strncpy(aim,src,3);
	printf("%s\n", aim);
	return 0;
}

你可能感兴趣的:(c语言,开发语言)