[英]Structs inside of structs in C
typedef char tCadena[TCAD];
typedef struct{
int i;
int f;
tCadena cola[TCOL];
}tCola;
typedef struct{
tCadena nombre[TCAD];
int numfich;
tCola cola;
}tImpresora;
typedef struct{
tImpresora impresora;
int ocupado;
}tElementoImpresora;
typedef tElementoImpresora tablaImp[MAXIMP];
So I have these structs, and I have a variable called thing
of type tablaImp
I want to go inside the struct and set the i
of the first structure to 0
. 所以我有这些结构,我有一个名为
tablaImp
类型的thing
,我想进入该结构并将第一个结构的i
设置为0
。 I tried with: 我尝试过:
tablaImp thing;
thing.impresora.cola.i=0;
But it tells me that its not a part of the structure. 但这告诉我它不是结构的一部分。 How can I do to go inside the first structure ?
如何进入第一个结构? Thanks.
谢谢。
tablaImp
is an array, you need to index it. tablaImp
是一个数组,您需要对其进行索引。
for (i = 0; i < MAXIMP; i++) {
thing[i].impresora.cola.i = 0;
}
thing
is an array (of structs), and you're trying to use it as if it were a struct: thing
是一个数组(结构),并且您试图像使用一个结构一样使用它:
typedef tElementoImpresora tablaImp[MAXIMP];
tablaImp thing;
thing.impresora.cola.i=0;
/* ↑ need an array index here */
typedef tElementoImpresora tablaImp[MAXIMP];
tablaImp thing;
thing.impresora.cola.i=0;
thing
is an array, you need to specify the array element: thing
是数组,则需要指定数组元素:
thing[0].impresora.cola.i = 0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.