问题
Can someone tell me how I can display a message box in C that can print variables?
I mean like this:
#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();
}
To look like this:
Variable
Variable x is equal to 5.
Thanks in advance!
回答1:
MessageBox itself doen't support printf
like formatting. You'll have to use snprintf for that:
char buf[1024];
snprintf(buf, 1024, "Variable x is equal to %d", x);
MessageBox(0, buf, "Variable", 0);
来源:https://stackoverflow.com/questions/21327458/how-to-use-the-windows-messagebox-c-function