TheJavaKing
TheJavaKing

Reputation: 43

How do I define the values of the variables inside a C Struct?

So I have the following:

struct semaphore{
int count; //or whatever value is needed
struct PCB *Sem_Queue;
};
struct semaphore Forks[5]; 
struct semaphore Doorman;
Doorman.count =4;

I want to set count = 4 for Doorman, but with the above code I get a syntax error. What am I doing wrong?

Upvotes: 1

Views: 50

Answers (1)

Anuroop Pendela
Anuroop Pendela

Reputation: 147

To the whole, your syntax is correct. Please verify the following points I mentioned:

->struct PCB *Sem_Queue :- there must be a valid declaration of struct PCB somewhere.

->Doorman.count =4 :- this one and above two statements(in your code) must be declared in any function body.

Upvotes: 1

Related Questions