strcpy函数的介绍
strcpy函数:把含有’\0’结束符的字符串复制到零一个地址空间,返回值的类型为char*
strDestination是目的字符串
strSource是源字符串
char *strcpy( char *strDestination, const char *strSource );
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
char *MyStrcpy(char *dest, const char *src)
{
char *p = dest;
assert((dest != NULL) && (src != NULL));
/*
断言,如果真值为假,它将先向stderr打印一条出错信息,然后通过调用abort来终止函数
*/
while ((*dest++ = *src++) != '\0')
{
;
}
return p;
}
int main()
{
char dest[20] = { 0 };
char *src = "hello";
strcpy(dest, src);
printf("%s\n", dest);
system("pause");
return 0;
}