有人能告诉我如何在 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();
}
Run Code Online (Sandbox Code Playgroud)
看起来像这样:
Variable
Variable x is equal to 5.
Run Code Online (Sandbox Code Playgroud)
提前致谢!
我在使用字符串方面遇到了一些未知问题.它只发生在这种算法的实例上:
由source.c
#include <stdio.h>
#include <string.h>
main()
{
int cur, max;
char ast[32];
printf("Enter the triangle's size: ");
scanf("%d", &max);
for(cur = 1; cur <= max; cur++)
{
strcat(ast, "*");
if(cur == 1)
{
printf("\n");
}
printf("%s\n", ast);
}
getch();
}
Run Code Online (Sandbox Code Playgroud)
有时候是这样的:
概述:用输入大小的星号(*)创建三角形的程序.
输入三角形的大小:5
■Z☼]vYⁿbv░↓@*
■Z☼]vYⁿbv░↓@**
■Z☼]vYⁿbv░↓@ *
■Z☼]vYⁿbv░↓@ **
■Z☼]vYⁿbv░↓@ *
它应该看起来像这样:
输入三角形尺寸:5
*
**
***
****
*****
Run Code Online (Sandbox Code Playgroud)
我不知道为什么.有人可以帮忙吗?:)