结构如下:

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}};

编译器在第一行捕获错误,“state[]states={”
“[”标记前需要标识符或“(”

最佳答案

更改为:

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中,[]应该在变量名之后,而不是在类型之后。

关于c - 结构数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22100704/

10-13 05:51