Memories of strcpy

It's been a long time since I wrote the implementation of library functions myself. Today I will write by hand, write the simple ones first, and then achieve them for the purpose.

#include<stdio.h>
#include<stdlib.h>

char *mystrcpy(char *dest,char *src)
{
	char *ptemp;
	if((NULL == dest) || (NULL == src))
	{
		printf("the is null pointer\n");
		return NULL;
	}

	ptemp = dest;

	while(*src)
	{
		*ptemp = *src;
		ptemp++;
		src++;
	}
	*ptemp = 0;
	return dest;
}

int main(int argc,char argv[])
{
	char a[] = "helloworld";
	char b[30];

	mystrcpy(b,a);

	printf("%s\n",b);

	return 0;
}

If you always learn, you must stick to the end if you choose. In addition to money, your life is to continuously defeat yourself ...

Published 53 original articles · praised 16 · visits 2213

Guess you like

Origin blog.csdn.net/m0_37757533/article/details/101212267