【问题标题】:Insert parameter in a string with C [duplicate]用C在字符串中插入参数[重复]
【发布时间】:2015-09-27 12:11:09
【问题描述】:

我想运行以下 OS X 命令:

md5 <<< 'password'

密码实际上应该是一个参数,因此我想知道如何将一个字符串“连接/插入”到另一个字符串中,就像我们可以使用printf 一样:

char password[] = "password";
//Something like this:
char command[] = ("md5 <<< '%s'", password);

在 C 中怎么可能?

【问题讨论】:

  • 谢谢。我不知道该怎么问,所以我也找不到答案。

标签: c string


【解决方案1】:

strcat 我认为可以完成这项工作:char *strcat(char *dest, const char *src)。

char res[30]; //malloc would be better
strcpy(res, "md5 <<< ");
strcat(res, password);

【讨论】:

  • 猜测不是最佳答案。你至少应该展示如何去做。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-19
  • 1970-01-01
相关资源
最近更新 更多