2015-05-11 82 views
0

我一直在这个项目上工作了一段时间,我想测试它,但我一直得到这个错误,我不知道该怎么做,我很困惑。这里是我的代码:错误前的预期表达式

typedef struct{ 
     int nr_pages; 
     int id; 
     int a,b; 
     int aux; 
    }information; 

    int main(){ 
    int i; 
    i = information.b; 
    //and more stuff happens 
    } 

,我总是正的错误也正是我宣布我= information.b 我在做什么错“之前的‘信息’预期的表达”?

+1

如果你的意图是有一个名为'information'的全局*变量*,那么从你的代码中删除关键字'typedef'。否则,你声明一个*类型*,而不是一个变量。 – WhozCraig

回答

4

您需要在使用它之前实例化结构。请尝试:

typedef struct{ 
    int nr_pages; 
    int id; 
    int a,b; 
    int aux; 
}information; 

int main(){ 

information info; 
info.b = 0; 
info.a = 0; 
... 
etc 
... 

int i = information.b; 
//and more stuff happens 
} 
0

您声明information作为一个类型而不是变量。这是typedef的用途。

i = ...在C语言中并不是一个声明,而是一个赋值。

相关问题