strcpy函数式怎么使用的?求解具体的运行方式,
越详细越好,新手一枚,老师没有讲,也不准备讲……
char str1[128] = { 0 };
char str2[128] = { "what the fuck!" };
strcpy(str1,str2); // 吧str2 拷贝到str1
没有再细了,1+1 = 2 没有那么多的为什么了
程序代码:
/* STRCPY.C: This program uses strcpy
* and strcat to build a phrase.
*/
#include <string.h>
#include <stdio.h>
void main( void )
{
char string[80];
strcpy( string, "Hello world from " );
strcat( string, "strcpy " );
strcat( string, "and " );
strcat( string, "strcat!" );
printf( "String = %s\n", string );
}
程序代码: * C语言标准库函数strcpy的一种典型的工业级的最简实现
* 返回值:
* 返回目标串的地址。
* 对于出现异常的情况ANSI-C99标准并未定义,故由实现者决定返回值,通常为NULL。
* 参数:
* strDestination
* 目标串
* strSource
* 源串
***********************/
char *strcpy(char *strDestination,const char *strSource)
{
assert(strDestination!=NULL && strSource!=NULL);
char *strD=strDestination;
while ((*strDestination++=*strSource++)!='\0');
return strD;
}百度百科
