+ =ではなく1
+ 1
=の2
ように、C で文字列を連結する方法。1
1
11
15857 次
5 に答える
9
文字列の連結が必要だと思います。
#include <stdio.h>
#include <string.h>
int main() {
char str1[50] = "Hello ";
char str2[] = "World";
strcat(str1, str2);
printf("str1: %s\n", str1);
return 0;
}
差出人:http ://irc.essex.ac.uk/www.iota-six.co.uk/c/g6_strcat_strncat.asp
于 2009-06-09T05:41:10.943 に答える
6
3 つ以上の文字列を連結するには、sprintf を使用できます。
char buffer[101];
sprintf(buffer, "%s%s%s%s", "this", " is", " my", " story");
于 2009-06-09T05:52:51.650 に答える
1
strcatAPIを見てみてください。十分なバッファスペースがあれば、ある文字列を別の文字列の最後に追加できます。
char[50] buffer;
strcpy(buffer, "1");
printf("%s\n", buffer); // prints 1
strcat(buffer, "1");
printf("%s\n", buffer); // prints 11
strcatのリファレンスページ
于 2009-06-09T05:39:24.050 に答える
1
「strcat」が答えですが、バッファサイズの問題に明示的に触れる例があるはずだと考えました。
#include <string.h>
#include <stdlib.h>
/* str1 and str2 are the strings that you want to concatenate... */
/* result buffer needs to be one larger than the combined length */
/* of the two strings */
char *result = malloc((strlen(str1) + strlen(str2) + 1));
strcpy(result, str1);
strcat(result, str2);
于 2009-06-09T05:54:16.593 に答える
0
strcat(s1、s2)。バッファサイズに注意してください。
于 2009-06-09T05:39:16.390 に答える