1. 程式人生 > >模擬實現strcpy 和strcat

模擬實現strcpy 和strcat

模擬實現strcpy :

char *My_strcpy(char *dest, const char *src)
{
	char *ret = dest;
	assert(NULL != dest);
	assert(NULL != src);
	while((*dest++ = *src++) != '\0')
	{
		;
	}
	return ret;
}

模擬實現strcat:

char *My_strcat(char *dest, const char *src)
{
	char *ret = dest;
	assert(NULL != dest);
	assert(NULL != src);
	while(*dest != '\0')
	{
		dest++;
	}
	while(*dest++ = *src++)
	{
		;
	}
	return ret;
}