当前位置: 代码迷 >> C语言 >> [转载]一段C语言做的音乐
  详细解决方案

[转载]一段C语言做的音乐

热度:297   发布时间:2007-10-26 18:53:51.0
[转载]一段C语言做的音乐

#include "dos.h"
#include "stdio.h"
#define time 10000 /*预定义节拍长度 time(一拍)*/
#define time0 5000 /*预定义半节拍长度 time0*/
#define time1 15000 /*预定义1.5节拍长度 time1*/
#define time2 20000 /*预定义2节拍长度 time2*/
#define time3 30000 /*预定义3节拍长度 time3*/
#define _a 262 /*预定义低音音符1~7*/
#define _b 294
#define _c 330
#define _d 349
#define _e 392
#define _f 440
#define _g 494
#define a 523/*预定义中音音符1~7*/
#define b 587
#define c 659
#define d 698
#define e 784
#define f 880
#define g 988
#define a_ 1047/*预定义高音音符1~7*/
#define b_ 1175
#define c_ 1319
#define d_ 1397
#define e_ 2568
#define f_ 1760
#define g_ 1976
main()
{
int i=0,j;
unsigned milliseconds;
int music[1000]={
f,time,
f,time,
g,time0,
f,time,
f,time,
g,time0,
f,time,
g,time,
a_,time,
g,time,
f,time,
g,time0,
f,time0,
d,time,
c,time,
a,time,
c,time,
d,time,
c,time,
c,time0,
a,time0,
_g,time,
f,time,
g,time,
a_,time,
g,time,
f,time,
g,time0,
f,time0,
d,time1,
c,time,
a,time,
c,time,
d,time,
c,time,
c,time0,
a,time0,
g,time1,
f,time,
f,time,
g,time1,
f,time,
f,time,
g,time1,
c,time,
d,time,
g,time0,
f,time0,
c,time,
d,time,
g,time0,
f,time0,
d,time0,
d,time,
c,time3
}
;
while(music[i]!='\0')
{
if(music[i]<=494) /*判断不是低音*/
{
milliseconds=music[i+1];

for(j=1;j<8;j++)
{
switch(j)
{
case 1: sound(a);
delay(milliseconds);break;
case 2: sound(b);
delay(milliseconds);break;
case 3: sound(c);
delay(milliseconds);break;
case 4: sound(d);
delay(milliseconds);break;
case 5: sound(e);
delay(milliseconds);break;
case 6: sound(f);delay(milliseconds);break;

case 7: sound(g);
delay(milliseconds);break;
}
nosound();
}
}
if(music[i]>494&&music[i]<988) /*判断不是中音*/
{
milliseconds=music[i+1];
for(j=1;j<8;j++)

{
switch(j)
{
case 1: sound(_a);
delay(milliseconds);break;
case 2: sound(_b);
delay(milliseconds);break;
case 3: sound(_c);
delay(milliseconds);break;
case 4: sound(_d);
delay(milliseconds);break;
case 5: sound(_e);
delay(milliseconds);break;
case 6: sound(_f);
delay(milliseconds);break;
case 7: sound(_g);
delay(milliseconds);break;
}
nosound();
}
}
if(music[i]>988) /*判断不是高音*/
{
milliseconds=music[i+1];
for(j=1;j<8;j++)
{
switch(j)
{
case 1: sound(a_);
delay(milliseconds);break;
case 2: sound(b_);
delay(milliseconds);break;
case 3: sound(c_);
delay(milliseconds);break;
case 4: sound(d_);
delay(milliseconds);break;
case 5: sound(e_);
delay(milliseconds);break;
case 6: sound(f_);
delay(milliseconds);break;
case 7: sound(g_);
delay(milliseconds);break;
}
nosound();
}
}
nosound();
i=i+2;
}
}

搜索更多相关的解决方案: define  C语言  音乐  节拍  定义  

----------------解决方案--------------------------------------------------------
用C-free编译没错,一运行就提示:undefinded reference to 'sound'
undefinded reference to 'delay'
……

用dev-cpp编译就提示:'sound' undeclared
'delay' undeclared
'nosound' undeclared

我怎么运行不出来呢?怎么编译?

----------------解决方案--------------------------------------------------------





我用Turbo C for Windows 集成实验与学习环境可以啊!!!

----------------解决方案--------------------------------------------------------



有能运行吗?说个话啊!!
----------------解决方案--------------------------------------------------------

c也能做音乐。。。很不错哎。。。


----------------解决方案--------------------------------------------------------
呵呵,真不好意思!我昨天用TC运行了,但是出错了!今天又运行了下,可以了,是我的TC没设好!我刚重设了下

C-free可以运行了,可是奇怪,按理说DEV-cpp本该可以的,为什么还是编译不通过!

谢谢你!

----------------解决方案--------------------------------------------------------

假设要让它在VC++6.0编译器上通过,该如何做呢?
在我的编译器里有提示这样的错误:
C:\Documents and Settings\Administrator\桌面\h.cpp(101) : error C2065: 'sound' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\h.cpp(102) : error C2065: 'delay' : undeclared identifier
C:\Documents and Settings\Administrator\桌面\h.cpp(116) : error C2065: 'nosound' : undeclared identifier
Error executing cl.exe.

h.exe - 3 error(s), 0 warning(s)
好像头文件#include "dos.h"定义了也没有用。。。。。
希望得到回复


----------------解决方案--------------------------------------------------------

我的能运行,但是没有声音啊.不知道怎么回事.我的是TC.


----------------解决方案--------------------------------------------------------

同8楼,关注中


----------------解决方案--------------------------------------------------------
不错!!楼主厉害
----------------解决方案--------------------------------------------------------
  相关解决方案