meow
meow

Reputation: 59

Expected expression before error

I've been working on this project for a while and I wanted to test it, but I keep getting this error and I have no idea what to do and I am very confused. Here is my code:

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

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

The error that I am always getting is "Expected expression before 'information'" exactly where I declare i = information.b What am I doing wrong?

Upvotes: 0

Views: 1096

Answers (2)

Jens Gustedt
Jens Gustedt

Reputation: 78903

You declare information as a type, not a variable. This is what the typedef is for.

And i = ... in the C terminology is not a declaration, but an assignment.

Upvotes: 0

rost0031
rost0031

Reputation: 1926

You need to instantiate the structure before using it. Try:

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
} 

Upvotes: 4

Related Questions