0

文字列にコンテンツを書き込み、同時に別の文字列をそこに入れることは可能ですか?

char str[50], *test;
scanf("%s", str);
test = "123 %s 123", str;
printf("%s\n", test);

scanf「abc」に書き込むことを検討してください

出力する方法は次のとおりです。

  • 123 abc 123
4

1 に答える 1

5

snprintf()のようprintfな書式設定を行い、結果を文字配列に入れるために使用できます。

char str[50], test[128];
scanf("%s", str);
snprintf(test, sizeof(test), "123 %s 123", str);
printf("%s\n", test);
于 2021-04-15T18:30:03.250 に答える