2014-02-28 233 views
1

這裏的是結構體:陣列結構

typedef struct state_machine{ 
char name; 
struct state_machine *next0; 
struct state_machine *next1; 
}state; 

和這裏的我試圖創建它們的陣列

state[] states = { 
     {'A', state+3, state+4}, 
     {'B', state, state+5}, 
     {'C', state+4, state }, 
     {'D', state+5, state+6}, 
     {'E', state+1, state+7}, 
     {'F', state+7, state+3}, 
     {'G', state+2, state+6}, 
     {'F', state+6, state+1}}; 

編譯器捕捉上第一行中的錯誤,「狀態[]狀態= { 「

預期標識符或 '(' 前 '[' 令牌

回答

5

更改爲:

state states[] = { 
     {'A', states+3, states+4}, //You probably meant states, since state is a type 
     {'B', states, states+5}, 
     {'C', states+4, states }, 
     {'D', states+5, states+6}, 
     {'E', states+1, states+7}, 
     {'F', states+7, states+3}, 
     {'G', states+2, states+6}, 
     {'F', states+6, states+1}}; 

C,所述[]應變量名後,類型後不。

+0

錯誤:在'state'之前的預期表達式 當我這樣做時 –

+1

@ user3365695:閱讀答案。你很可能忘了改變'state + 4'到'states + 4'。 –

+0

:falmpalm:不敢相信我沒有看到 –