strcat连接a和b而不实际更改a或b

tin*_*101 1 c string concatenation strcpy strcat

我知道我可以这样说

    strcat( a, b );
    int alen = strlen( a );
    printf("a and b concatenated = %s and its length is %d\n", a, alen );
Run Code Online (Sandbox Code Playgroud)

但是,我想保留一个,因此我正在尝试使用更多类似这样的内容:

    strcat( a, b );
    int xlen = strlen( x );
    printf("a and b concatenated = %s and its length is %d\n", x, xlen );
Run Code Online (Sandbox Code Playgroud)

如何用strcat固定第一行,以便将a和b连接到x中?

Am_*_*ful 5

您应该使用以下内容:

strcpy(x,a);
strcat(x,b);
int xlen = strlen(x);
printf("a and b concatenated = %s and its length is %d\n", x, xlen );
Run Code Online (Sandbox Code Playgroud)

瞧,就是这样。