char * strcpy(char *dest,char *sour);
c = strcpy(a,b)
a只能是空间足够大的字符串数据对象,比如说数组。a的空间不够大,将导致越界,不产生异常,但修改相临存储区的内容。
b可以是指向字符串的指针或字符串数组,也可以是字符串常量。
c可以是指向字符串的指针或字符串常量。
strcpy的高级用法:
#include
<
stdio.h
>
#include < string .h >
int main() ... {
char *orig = "beast";
char *ps;
char copy[40] = "be the best that you can be";
puts(orig);
puts(copy);
ps= strcpy(copy+7,orig);
puts(copy);
puts(ps);
getchar();
return 0;
}
#include < string .h >
int main() ... {
char *orig = "beast";
char *ps;
char copy[40] = "be the best that you can be";
puts(orig);
puts(copy);
ps= strcpy(copy+7,orig);
puts(copy);
puts(ps);
getchar();
return 0;
}
结果是:beast
be the best you can be
be the beasat
beast
另外:strcpy()不检查目标字符川是否能容纳下源字符串,解决的办法是尽量分配大的空间,或者用strncpy()