%s 在字符串文字中是什么意思?

3 printf

我正在查看我在其中找到的以下代码libgksu,我想知道%s字符串内部的作用。我无法为此使用 Google,因为它会在搜索过程中删除诸如百分位数之类的字符,只留下“s”作为搜索词。

if (!strcmp(context->user, "root"))
        msg = g_strdup_printf (_("<b><big>Enter your password to perform"
                     " administrative tasks</big></b>\n\n"
                     "The application '%s' lets you "
                     "modify essential parts of your "
                     "system."),
                   command);
Run Code Online (Sandbox Code Playgroud)

这段代码的目的是为用户在 Linux 上请求超级用户权限时看到的对话框提供文本,如下图所示

在此处输入图片说明

%s这种情况下是包含请求权限的应用程序的名称的变量,但它不是那样简单,因为我已经看到了%s整个完全不同的上下文中的代码中使用。比如else上面if语句的组成部分是

else
    msg = g_strdup_printf (_("<b><big>Enter your password to run "
                 "the application '%s' as user %s"
                 "</big></b>"),
               command, context->user);
Run Code Online (Sandbox Code Playgroud)

并且%s用于标记应用程序和用户的名称。有人可以告诉我它的用途%s是什么以及在哪里可以找到有关它使用的更多信息吗?我假设这是一个正则表达式,但正如我之前所说,我无法通过 Google 找到答案。

Bis*_*ook 5

%s 是字符串的 C 格式说明符。

msg = g_strdup_printf (_("<b><big>Enter your password to run "
                         "the application '%s' as user %s"
                         "</big></b>"),
                         command, context->user);
Run Code Online (Sandbox Code Playgroud)

意思是“在您看到第一个的地方%s,将其替换command为字符串形式的内容,而在您看到第二个的地方%s,将其替换context->user为字符串形式的内容。