简体   繁体   English

无法为结构分配内存,错误:请求非结构或联合的成员“ ****”

[英]Cannot allocate memory for struct, error: request for member '****' in something not a structure or union

I am recently doing a school homework and I am stuck, in creating dynamic array of structs. 最近,我在做学校作业,但仍无法创建动态的结构数组。 I was looking everywhere, but no answer helped me, so can you please look at my code and help me, what is wrong? 我到处都在看,但是没有答案能帮助我,所以请您看看我的代码并帮助我,这是怎么回事? I keep getting error: C:\\kof\\test1\\main.c|29|error: request for member 'lenght' in something not a structure or union| 我不断收到错误消息:C:\\ kof \\ test1 \\ main.c | 29 |错误:请求成员'lenght'的原因不是结构或联合|

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct time
{
int mi;
int ho;
int dn;
int me;
int ro;
};

struct journey
{
int lenght;
struct time zac;
struct time kon;
int tank;
int price;
};


int main ()
{
struct journey *fail;
struct journey *b=(struct journey*) malloc (1*sizeof(struct journey));
fail=b;
fail.lenght=5;
return 0;
}

Since *fail is a pointer of type struct journey, you access its elements using the ' -> ' notation and not using the . 由于*fail是struct travel类型的指针,因此您可以使用' -> '表示法而不是使用其访问其元素. notation as stated here 记数法表示这里

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

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