文字列をコピーするstrcpy関数について以下にCサンプルコードおよび実行例を記します。
c-top.html is not found or not readable.#include <string.h>
char *strcpy(char *dest, const char *src);
&ref(): File not found: "strcpy.c" at page "文字列/文字列をコピーする・strcpy"; (改行コードLF)
#include <stdio.h> #include <string.h> int main(void) { char *p1 = "IT SUPPORT SAKURA"; char p2[255]; memset(p2, '\0', sizeof(p2)); printf("Before : p2 = %s\n", p2); strcpy(p2, p1); printf("After : p2 = %s\n", p2); return 0; }
コンパイルし実行した結果を以下に記します。
$ gcc strcpy.c -o strcpy $ ./strcpy Before : p2 = After : p2 = IT SUPPORT SAKURA
コピー前、コピー後のが表示されています。
以上、strcpyのCサンプルコードでした。
c-btm.html is not found or not readable.