[問題] 用C寫音樂程式

看板C_and_CPP作者 (ㄚ春)時間17年前 (2009/03/10 18:12), 編輯推噓1(105)
留言6則, 3人參與, 最新討論串1/3 (看更多)
#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

03/10 18:15, , 1F
在 system("pause") 與 } 間插一行 return 0;
03/10 18:15, 1F

03/10 18:16, , 2F
void main() 改成 int main();
03/10 18:16, 2F

03/10 18:16, , 3F
上面的 ; 是多餘的 int main() 就好
03/10 18:16, 3F

03/10 18:21, , 4F
感謝你 沒有錯了 可是...按下執行後畫面就會跳掉@@
03/10 18:21, 4F

03/11 00:42, , 5F
唔 ... 都是low level I/O耶,這是給Win32跑的 ??
03/11 00:42, 5F

03/11 11:05, , 6F
小弟剛學@@ 那個是什麼?? 我用學校寫C的平台跑的><
03/11 11:05, 6F
文章代碼(AID): #19jZqOcj (C_and_CPP)
文章代碼(AID): #19jZqOcj (C_and_CPP)