文字列コピー

462 ワード

#include 
using namespace std;


char* mystrcpy(char *dest, char *sour)
{
	char *r = dest;
	while (*sour != '\0')
	{
		*(dest++) = *(sour++);
	}
	return r;
}


int main()
{
	char* str1 = (char*)"ADCs";
	char* str2 = (char*)malloc(sizeof(char) * 5);
	memset(str2, 0x00, 5);
	mystrcpy(str2, str1);

	cout << str1 << endl;
	cout << str2 << endl;
	free(str2);
	return 0;
}