#include<stdio.h> #include<graphics.h> #include <mmsystem.h> #include<stdbool.h> #pragma comment(lib,"winmm.lib") int main() { /* IMAGE bk; loadimage(&bk, "./1.png"); int width = bk.getwidth(); int height = bk.getheight(); IMAGE background; loadimage(&background, "./1.png"); width = background.getwidth(); height = background.getheight(); initgraph(width, height); putimage(0, 0, &background); */ mciSendString("open 1.mp3", 0, 0, 0); mciSendString("play 1.mp3", 0, 0, 0); while (true); return 0; }找找问题
时间: 2024-01-28 07:05:32 浏览: 81
#include<stdio.h>
这段代码的问题在于 while 循环会一直运行,导致程序无法正常结束,需要手动强制关闭。建议将 while 循环替换为一个等待用户输入的语句,例如:
```c
#include<stdio.h>
#include<graphics.h>
#include<mmsystem.h>
#include<stdbool.h>
#pragma comment(lib,"winmm.lib")
int main() {
IMAGE bk;
loadimage(&bk, "./1.png");
int width = bk.getwidth();
int height = bk.getheight();
IMAGE background;
loadimage(&background, "./1.png");
width = background.getwidth();
height = background.getheight();
initgraph(width, height);
putimage(0, 0, &background);
mciSendString("open 1.mp3", 0, 0, 0);
mciSendString("play 1.mp3", 0, 0, 0);
printf("Press any key to exit...\n");
getchar(); // 等待用户输入
return 0;
}
```
这样程序就会在用户按下任意键后正常退出,避免了无法正常结束的问题。
阅读全文