作者a1013944 (ㄚ春)
看板C_and_CPP
標題[問題] 用C寫音樂程式
時間Tue Mar 10 18:12:39 2009
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
void delay(secs)
float secs;
{
clock_t end;
end=(int)(secs*CLOCKS_PER_SEC)+clock();
while(clock()<end);
}
static int portvalue=0;
void sound(unsigned freq)
{
int portdata;
_outp(0x43,0xb6);
freq=(unsigned)(1193180L/freq);
_outp(0x42,(char)freq);
_outp(0x42,(char)(freq>>8));
portdata=_inp(0x61);
if(portvalue==0)
portvalue=portdata;
_outp(0x61,portvalue | 0x3);
}
void nosound()
{
_outp(0x61,portvalue) ;
}
void main()
{
unsigned freq[]={523,587,659,523,523,587,659,523,
659,698,784, 0,659,698,784, 0,
784,880,784,698,659,523,
784,880,784,698,659,523,
523,329,523, 0,523,392,523, 0};
double duration[]={0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,
0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,
0.25,0.25,0.25,0.25,0.5,0.5,
0.25,0.25,0.25,0.25,0.5,0.5,
0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5 };
int i;
for(i=0;i<36;i++)
{
if(freq[i]>0)
sound(freq[i]);
delay(duration[i]);
}
nosound();
system("pause");
}
他回給我的是錯誤 在32行
[Warning] return type of 'main' is not `int'
有人可以幫我改一下嗎 謝謝!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.123.237.33
→ james732:在 system("pause") 與 } 間插一行 return 0; 03/10 18:15
→ james732:void main() 改成 int main(); 03/10 18:16
→ james732:上面的 ; 是多餘的 int main() 就好 03/10 18:16
→ a1013944:感謝你 沒有錯了 可是...按下執行後畫面就會跳掉@@ 03/10 18:21
推 Bencrie:唔 ... 都是low level I/O耶,這是給Win32跑的 ?? 03/11 00:42
→ a1013944:小弟剛學@@ 那個是什麼?? 我用學校寫C的平台跑的>< 03/11 11:05