1 char *p = "hello";//5 个长度 2 3 int len = strlen(p)+1 ; 4 5 //char *str = (char *)malloc(sizeof(char)*len); 6 char str[90] = "nihaoma"; 7 //memset(str, 0, len); 8 //strcpy(str, p); 9 strcat(str, p);//str 必须有初始化 10 //memcpy(): 需要为 str 多分配一个空间,然后系统才能自动添加 \0 11 //memcpy(str, p, len); 12 len = strlen(str); 13 14 printf("strlen(str):%d\n", len); 15 printf("%s\n", str); 16 17 //char destination[25]; 18 //char *blank = " ", *c = "C++", *Borland = "Borland"; 19 20 ////strcpy 自动加 \0 那么后面使用 strcat 也不会影响 21 //strcpy(destination, Borland); 22 //strcat(destination, blank); 23 //strcat(destination, c); 24 25 //printf("%s\n", destination); 26 27 28 29 system("pause");
时间: 2024-10-13 22:48:49