C语言字符拼接的技能有哪几种
在C语言中,字符拼接通常使用字符串的拼接方法来实现。以下是一些C语言字符拼接的经常使用技能:
char str1[50] = "Hello";
char str2[] = "World";
strcat(str1, str2);
printf("%s
", str1); // 输出:HelloWorld
char str[50];
int num = 123;
sprintf(str, "The number is %d", num);
printf("%s
", str); // 输出:The number is 123
char str1[50] = "Hello";
char str2[] = "World";
strncat(str1, str2, 3);
printf("%s
", str1); // 输出:HelloWor
char str1[50] = "Hello";
char str2[] = "World";
char *p = str1;
while (*p) {
p++;
}
while (*str2) {
*p++ = *str2++;
}
*p = '