如何使用Windows MessageBox()C函数?

如何使用Windows MessageBox()C函数?,c,windows,messagebox,C,Windows,Messagebox,有人能告诉我如何用C显示一个可以打印变量的消息框吗 我的意思是: #include <stdio.h> #include <windows.h> main() { int x = 5; MessageBox(0, "Variable x is equal to %d", "Variable", 0); /* Where do I specify the variable so that 5 will display?*/ getch(

有人能告诉我如何用C显示一个可以打印变量的消息框吗

我的意思是:

#include <stdio.h>
#include <windows.h>

main()
{
    int x = 5;
    MessageBox(0, "Variable x is equal to %d", "Variable", 0); 
    /* Where do I specify the variable so that 5 will display?*/

    getch();
}
          Variable

 Variable x is equal to 5.
提前谢谢

本身不支持类似于
printf
的格式。为此,您必须使用:

char buf[1024];
snprintf(buf, 1024, "Variable x is equal to %d", x);

MessageBox(0, buf, "Variable", 0);

您的
main
函数缺少返回类型@我的编译器通常不需要它。此外,我做这个只是为了测试可能的解决方案。我会永远记住,当为real@Wix编码时,作为一个建议,在测试程序中也要这样做。它可以创建肌肉记忆,并使您在“真实”应用程序中更不容易忘记它。请记住,snprintf仅在C++11及更高版本中可用。@urzeit:我们这里说的是C。从我记事起,它就一直在标准库中。没有注意到C标记。