#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
int main(void){
char a[] = "jian";
char b[] = "kedou";
int lena = sizeof(a)-1;
int lenb = sizeof(b)-1;
int shaque_len = lena + lenb+1;//留一个位置给\0;
printf("合并后的字符串加上反斜杠0的长度为%d\n", shaque_len);
char *p = (char *)malloc(sizeof(char) * shaque_len);
int index = 0;
while (index < lena){
p[index] = a[index];
index++;
}
while (b[index-lena]!='\0'){
p[index] = b[index-lena];
index++;
}
p[index] = '\0';
printf("%s", p);
free(p);
system("pause");
return EXIT_SUCCESS;
}
c语言合并2个字符串
最新推荐文章于 2024-07-11 10:09:16 发布