strcpy()函数有两个属性:
【1】其返回值是*char类型,即返回的第一个参数的值是一个字符的地址。
【2】第一个参数不必指向数组的开始。
程序示例
#include<stdio.h>
#include<string.h>
#define WORDS "beats"
#define SIZE 40
int main()
{
const char *orig = WORDS;
char copy[SIZE] = "be the best that you can be.";
char *ps;
puts(orig);
puts(copy);
ps = strcpy(copy + 7, orig);
puts(copy);
puts(ps);
puts(copy + 13);
return 0;
}
输出示例
beats
be the best that you can be.
be the beats
beats
hat you can be.
在该例中,空字符覆盖了copy数组中that的第一个t,copy数组其余的字符还保留在数组中。
在最后的输出函数中,从此空字符开始,到数组本来的空字符截住,直接输出。