简体   繁体   English

在不是结构或联合的东西中请求成员“东西”

[英]Request for member 'something' in something not a structure or union

So hi guys, im on colleague and i have to do a program in c to sort simulate a system of tickets in a reparation store.嗨,伙计们,我是同事,我必须用 c 语言编写一个程序来排序模拟维修商店中的票证系统。

I made this like basically every type of ticket has a structure.我做了这个,就像基本上每种类型的票都有一个结构。

this is an example.这是一个例子。

typedef struct reparacao
typedef struct  entrega
{
char servico_ent;
int numtick_ent;
int dia_entrada_ent;
int mes_entrada_ent;
int ano_entrada_ent;
int hora_entrada_ent;
int min_entrada_ent;
int hora_atend_ent;
int min_atend_ent;  
int balcao_ent;
char cond_ent[100];
float valor_pagar;
};
entrega entrega1[100];

and then i write to get the time然后我写信来争取时间

`time_t t = time(NULL);
struct tm tm = *localtime(&t);
printf("%d-%d-%d %d:%d\n", tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900, tm.tm_hour, tm.tm_min);
// verificar se o horário está entre as 8H e as 22H
if(tm.tm_hour<8 || tm.tm_hour>=22) 
{
    printf("\nNao pode recolher ticket. Horario: 8:00h-21:59h\n\n");
}else
    {
    //Guardar dados no vetor
        printf("Ticket numero %d\n\n", natend_ent);
        entrega1[j].numtick_ent = natend_ent;
        entrega1[j].servico_ent = 'Entrega';
        entrega1[j].dia_entrada_ent = tm.tm_mday;
        entrega1[j].mes_entrada_ent = tm.tm_mon+1;
        entrega1[j].ano_entrada_ent = tm.tm_year + 1900;
        entrega1[j].hora_entrada_ent = tm.tm_hour;
        entrega1[j].min_entrada_ent = tm.tm_min;
        natend_ent++;
        j++;
    }`    

What can it is causing the error "Request for member 'blablabla' in something not a structure or union"?是什么导致了错误“在非结构或联合体中请求成员‘blablabla’”?

You have declared entrega1 as an array whose elements are of type entrega , but the code presented does not define type entrega , and in particular, that identifier is not defined as representing a structure type.您已将entrega1声明为一个数组,其元素的类型为entrega ,但提供的代码并未定义类型entrega ,特别是,该标识符未定义为表示结构类型。 Your compiler ought to be complaining about that, too.你的编译器也应该抱怨这一点。 It is often best to start handling warnings and errors from the top, because it is not uncommon for bad code in one place to cause multiple errors.通常最好从顶部开始处理警告和错误,因为在一处不良代码导致多个错误的情况并不少见。

Specifically in this case, your typedef keywords do nothing because you are not declaring any identifier for them to apply to.特别是在这种情况下,您的typedef关键字什么都不做,因为您没有声明任何标识符供它们应用。 Perhaps you have the relatively common misunderstanding that typedef is used for defining new types, especially structure types.也许您有一个相对常见的误解,即typedef用于定义新类型,尤其是结构类型。 It is not.它不是。 It is for defining aliases for types.它用于定义类型的别名 The type you have declared is struct entrega (the struct keyword is part of the type name), and you may use that everywhere.声明该类型是struct entrega (该struct的关键字是类型名称的一部分),并且,你可以使用随处可见。 If you want to be able to omit the struct part, then the correct way to use a typedef for that world be:如果您希望能够省略struct部分,那么为该世界使用 typedef 的正确方法是:

typedef struct entrega {
    char servico_ent;
    /* ... other members ... */
    float valor_pagar;
} entrega;

Equivalently, you could separate the typedef from the structure definition:等效地,您可以将 typedef 与结构定义分开:

struct entrega {
    char servico_ent;
    /* ... other members ... */
    float valor_pagar;
};

typedef struct entrega entrega;

The latter is perhaps more instructive than the former.后者或许比前者更有指导意义。 It may also be instructive that you are permitted to swap the order of the typedef and the structure definition.允许您交换typedef和结构定义的顺序也可能是typedef的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM