「C言語」strcpy関数で文字列をコピーするサンプル
構文
char *strcpy(char *s1, const char *s2);
文字列のコピー
s1 コピー先
s2 コピー元
使用例
#include <stdio.h>
#include <string.h>
int main ()
{
char cftA[20] = "TEST";
char cftB[20] = "kk7788";
/*文字型配列->文字型配列 copy */
strcpy(cftA, cftB);
printf("cftB to cftA copy result:%s\n", cftA);
/* 文字列->文字型配列 copy */
strcpy(cftA, "this is a test");
printf("cftA value:%s\n", cftA);
return 0;
}
実行結果
cftB to cftA copy result:kk7788
cftA value:this is a test