C语言多线程问题:如何让下面两段代码同时运行 就是播放生日歌的同时输出文字
发布网友
发布时间:2022-04-26 18:41
我来回答
共1个回答
热心网友
时间:2023-10-21 14:00
#include <Windows.h>
#include <stdio.h>
#include <process.h>
VOID MyPlaySound(LPVOID lp)
{
unsigned FREQUENCY[]={392,392,440,392,523,494,
392,392,440,392,587,523,
392,392,784,659,523,494,440,
698,698,659,523,587,523,
392,392,440,392,523,494,
392,392,440,392,587,523,
392,392,784,659,523,494,440,
698,698,659,523,587,523};
unsigned DELAY[]={375,125,500,500,500,1000,
375,125,500,500,500,1000,
375,125,500,500,500,500,1000,
375,125,500,500,500,1000,
375,125,500,500,500,1000,
375,125,500,500,500,1000,
375,125,500,500,500,500,1000,
375,125,500,500,500,1000};
int CIRCLE;
for(CIRCLE=0;CIRCLE<50;CIRCLE++)
{
Beep(FREQUENCY[CIRCLE],DELAY[CIRCLE]);
}
}
VOID MyPrint(LPVOID lp)
{
int i;
char a[10][4]={"一","二","三","四","五","六","七","八","九","十"};
for(i=0;i<10;i++)
{
printf("%s",a[i]);
Sleep(500);
}
}
int main()
{
_beginthread(MyPlaySound, 0, NULL);
_beginthread(MyPrint, 0, NULL);
Sleep(20000);
return 0;
}
编译之前记得把项目属性里改成多线程方案的.不然会出错.我是在VS2010下编译的.