參考書本範例,卻錯誤一堆的C語言範例..

看板Programming作者時間18年前 (2007/07/19 02:01), 編輯推噓7(700)
留言7則, 1人參與, 最新討論串1/2 (看更多)
請教一下,以下的程式是在c語言課本上看到的 我在dev-c++內編譯,我的系統會給我這樣的回應: 11 C:\Documents and Settings\123test\桌面\1.c parse error before '{' token 13 C:\Documents and Settings\123test\桌面\1.c parse error before "for" 14 C:\Documents and Settings\123test\桌面\1.c parse error before numeric constan t 14 C:\Documents and Settings\123test\桌面\1.c conflicting types for `functiona' 4 C:\Documents and Settings\123test\桌面\1.c previous declaration of `functiona' 14 C:\Documents and Settings\123test\桌面\1.c [Warning] data definition has no type or storage class 16 C:\Documents and Settings\123test\桌面\1.c parse error before string constant 16 C:\Documents and Settings\123test\桌面\1.c [Warning] data definition has no type or storage class 21 C:\Documents and Settings\123test\桌面\1.c conflicting types for `functiona' 14 C:\Documents and Settings\123test\桌面\1.c previous declaration of `functiona' 我的程式碼如下 麻煩各位幫忙了 謝謝! #include<dos.h> #include<stdlib.h> #define SIZE 100 void functiona(int a[], int size); main() { int a[SIZE] = {0}; int i =0; for(i = 0; i <100; i++){a[i] = {1};} for(i = 0; i <100; i++){printf("%d",a[i]);} functiona(a , SIZE); //printf("\n%.2f",2.13); system("PAUSE"); } void functiona(int a[], int size) { int i,total = 0; for(i = 0; i < 100; i++) total += a[i]; system("PAUSE"); } -- ┌─────KKCITY─────┐KKMAN團隊 全新力作 ◎◎KKBOX◎◎ bbs.kkcity.com.tw 知名歌手通通都有 所有新歌想聽就聽 └──From:218.169.106.32 ──┘※※ 內容豐富多元的線上音樂台 ※※ --

07/19 02:17, , 1F
這本書應該很古老了, 很久(二十年XD?)以前
07/19 02:17, 1F

07/19 02:17, , 2F
c 還沒採那麼嚴的的 strong-typing policy
07/19 02:17, 2F

07/19 02:20, , 3F
function 沒給return type 也可以 compile
07/19 02:20, 3F

07/19 02:20, , 4F
main 前加個 int, 然後return 個 0 吧
07/19 02:20, 4F

07/19 02:20, , 5F
然後 a[i]={1} 是錯的 XD
07/19 02:20, 5F

07/19 02:23, , 6F
(沒過主要是a={1}, main 的 return type
07/19 02:23, 6F

07/19 02:24, , 7F
好像其實沒影響 XD)
07/19 02:24, 7F
文章代碼(AID): #16dbLZ00 (Programming)
文章代碼(AID): #16dbLZ00 (Programming)