📄 strcpy.c
字号:
/* Demonstrates strcpy(). */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char source[] = "The source string.";
int main( void )
{
char dest1[80];
char *dest2, *dest3;
printf("\nsource: %s", source );
/* Copy to dest1 is okay because dest1 points to */
/* 80 bytes of allocated space. */
strcpy(dest1, source);
printf("\ndest1: %s", dest1);
/* To copy to dest2 you must allocate space. */
dest2 = (char *)malloc(strlen(source) +1);
strcpy(dest2, source);
printf("\ndest2: %s\n", dest2);
/* Copying without allocating destination space is a no-no. */
/* The following could cause serious problems. */
/* strcpy(dest3, source); */
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -