C string append

后端 未结 10 1295
野趣味
野趣味 2020-12-01 06:21

I want to append two strings. I used the following command:

new_str = strcat(str1, str2);

This command changes the value of str1

10条回答
  •  抹茶落季
    2020-12-01 06:54

    I needed to append substrings to create an ssh command, I solved with sprintf (Visual Studio 2013)

    char gStrSshCommand[SSH_COMMAND_MAX_LEN]; // declare ssh command string
    
    strcpy(gStrSshCommand, ""); // empty string
    
    void appendSshCommand(const char *substring) // append substring
    {
      sprintf(gStrSshCommand, "%s %s", gStrSshCommand, substring);
    }
    

提交回复
热议问题