How to use the Windows MessageBox() C function?
11,337
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);
Author by
Wix
Updated on June 26, 2022Comments
-
Wix almost 2 years
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!