Re: [問題] 請教struct宣告問題
看板C_and_CPP (C/C++)作者descent (「雄辯是銀,沉默是金」)時間12年前 (2013/10/07 16:25)推噓4(4推 0噓 17→)留言21則, 7人參與討論串2/2 (看更多)
這個還真難解釋
int main()
{
char suit[];
suit[] = "Hearts";
}
你能理解這樣的寫法是有問題的嗎?
若可以,
你的 struct 寫法就類似這樣。
一般是寫這樣 char suit[] = "Hearts"; suit 是 array, 大小是 7,
我想你把這兩種語法搞混了。
不過 char suit[]; 這個是什麼東西, 有版友可以解個疑惑嗎?
array 可以不指定大小嗎?
答案這麼簡單, 自己沒先試試看
a.c:4:8: error: array size missing in ‘suit’
char suit[];
compiler 不給過
※ 引述《youneverknow (睡覺一直想)》之銘言:
: 開發平台(Platform): Code Blocks
: 額外使用到的函數庫(Library Used): 無
: 問題(Question):
: 宣告 struct Card,當中的char陣列無法被拉到main使用
:
: 餵入的資料(Input):
: 預期的正確結果(Expected Output):
: 錯誤結果(Wrong Output):
: \card13.cpp||In function 'int main()':|
: \card13.cpp|15|error: expected primary-expression before ']' token|
: \card13.cpp|16|error: expected primary-expression before ']' token|
: ||=== Build finished: 2 errors, 0 warnings (0 minutes, 0 seconds) ===|
: 程式碼(Code):(請善用置底文網頁, 記得排版)
: http://ideone.com/YlhyBW
: 補充說明(Supplement):
: 新新手,正在學習中,請多包涵
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.125.239.51
推
10/07 16:32, , 1F
10/07 16:32, 1F
→
10/07 16:40, , 2F
10/07 16:40, 2F
→
10/07 16:40, , 3F
10/07 16:40, 3F
→
10/07 16:41, , 4F
10/07 16:41, 4F
→
10/07 16:50, , 5F
10/07 16:50, 5F
→
10/07 16:51, , 6F
10/07 16:51, 6F
※ 編輯: descent 來自: 59.125.239.51 (10/07 16:57)
推
10/07 17:01, , 7F
10/07 17:01, 7F
推
10/07 17:50, , 8F
10/07 17:50, 8F
→
10/07 17:50, , 9F
10/07 17:50, 9F
→
10/07 17:53, , 10F
10/07 17:53, 10F
→
10/07 17:56, , 11F
10/07 17:56, 11F
→
10/07 17:57, , 12F
10/07 17:57, 12F
→
10/07 17:57, , 13F
10/07 17:57, 13F
→
10/07 21:04, , 14F
10/07 21:04, 14F
推
10/07 22:28, , 15F
10/07 22:28, 15F
→
10/07 23:06, , 16F
10/07 23:06, 16F
→
10/07 23:13, , 17F
10/07 23:13, 17F
→
10/07 23:14, , 18F
10/07 23:14, 18F
→
10/07 23:15, , 19F
10/07 23:15, 19F
→
10/07 23:35, , 20F
10/07 23:35, 20F
→
10/07 23:36, , 21F
10/07 23:36, 21F
討論串 (同標題文章)
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章