「C言語」strcat関数で文字列を連結するサンプル

構文
char *strcat(char * restrict s1,const char * restrict s2
);
文字列を連結します。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
#include <stdio.h>
#include <string.h>
int main(void)
{
char cftA[50], cftB[40];
// 文字列をコピー
strcpy(cftA, "Welcome study");
strcpy(cftB, "in arkgame.com");
printf("cftA value: %s, cftB value:%s\n", cftA, cftB);
// 文字列を連結
strcat(cftA, cftB);
printf("cftA + cftB result: %s\n", cftA);
return 0;
}
#include <stdio.h> #include <string.h> int main(void) { char cftA[50], cftB[40]; // 文字列をコピー strcpy(cftA, "Welcome study"); strcpy(cftB, "in arkgame.com"); printf("cftA value: %s, cftB value:%s\n", cftA, cftB); // 文字列を連結 strcat(cftA, cftB); printf("cftA + cftB result: %s\n", cftA); return 0; }
#include <stdio.h>
#include <string.h>

int main(void)
{
  char cftA[50], cftB[40];
  
  // 文字列をコピー
  strcpy(cftA, "Welcome study");
  strcpy(cftB, "in arkgame.com");
  printf("cftA value: %s, cftB value:%s\n", cftA, cftB);

  // 文字列を連結
  strcat(cftA, cftB);
  printf("cftA + cftB result: %s\n", cftA);
  return 0;
}

実行結果
cftA value: Welcome study, cftB value:in arkgame.com
cftA + cftB result: Welcome studyin arkgame.com

C言語

Posted by arkgame