我最近正在做学校作业,但在创建动态结构数组时遇到了困难。我到处寻找,但没有答案帮助我,所以你能看看我的代码并帮助我,出了什么问题吗? 我不断收到错误: C:\kof\test1\main.c|29|错误:请求非结构或 union 中的成员“长度”|
#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;
}
最佳答案
由于 *fail
是 struct Journey 类型的指针,因此您可以使用“->
”表示法而不是使用 来访问其元素。
符号如所述 here
关于无法为结构分配内存,错误: request for member '****' in something not a structure or union,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20719784/