1.strcpy全部替换原字符串 #define _CRT_SECURE_NO_WARNINGS 1#includestdio.h#includestring.hint main() {char arr1[] = "hello world";char arr2[] = "##################";//用arr1替换arr2strcpy(arr2, arr1);printf("%s", arr2);return 0;}
1.strcpy全部替换原字符串
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main() {
char arr1[] = "hello world";
char arr2[] = "##################";
//用arr1替换arr2
strcpy(arr2, arr1);
printf("%s", arr2);
return 0;
}
strcpy在替换时会携带/0,把arr2变为hello world/0######
printf在打印字符串时读取到/0为止,所以只会打印hello world。
2.memset部分替换原字符串
memory set 即内存设置
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<string.h>
int main() {
char arr1[] = "hello world";
memset(arr1, '#', 5);
printf("%s", arr1);
return 0;
}
memset仅仅把前五项替换为#,不会携带/0,所以打印结果为##### world