Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何定义C结构中变量的值?_C_Struct - Fatal编程技术网

如何定义C结构中变量的值?

如何定义C结构中变量的值?,c,struct,C,Struct,因此,我有以下几点: struct semaphore{ int count; //or whatever value is needed struct PCB *Sem_Queue; }; struct semaphore Forks[5]; struct semaphore Doorman; Doorman.count =4; 我想为门卫设置count=4,但是使用上面的代码我得到了一个语法错误。我做错了什么?总的来说,你的语法是正确的。请核实我提到的以下几点: ->struct PCB

因此,我有以下几点:

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

我想为门卫设置count=4,但是使用上面的代码我得到了一个语法错误。我做错了什么?

总的来说,你的语法是正确的。请核实我提到的以下几点:

->struct PCB*Sem_Queue:-必须在某个地方有一个有效的struct PCB声明


->Doorman.count=4:-这一条及以上两条语句(在代码中)必须在任何函数体中声明。

全局范围内(函数之外)不能有语句(如
Doorman.count=4;
)。我可以证实这不是问题所在。你的第二点是什么导致了我的问题,谢谢!