gpt4 book ai didi

c - 访问函数中的结构元素

转载 作者:行者123 更新时间:2023-11-30 17:43:07 25 4
gpt4 key购买 nike

当我编译下面的代码时,出现错误

snippet.c:24:24: error: request for member ‘px’ in something not a structure or union
snippet.c:25:24: error: request for member ‘py’ in something not a structure or union
snippet.c:27:22: error: request for member ‘x’ in something not a structure or union
snippet.c:27:45: error: request for member ‘y’ in something not a structure or union
snippet.c:31:14: error: request for member ‘x’ in something not a structure or union
snippet.c:35:16: error: request for member ‘y’ in something not a structure or union
snippet.c:39:25: error: request for member ‘px’ in something not a structure or union
snippet.c:40:25: error: request for member ‘py’ in something not a structure or union

下面的代码

struct list{
int x;
int y;
int f;
int g;
int h;
int px;
int py;
};

void history(int j, struct list *path[], struct list *closelist[], struct list *start, int *fxele);
void history(int j, struct list *path[], struct list *closelist[], struct list *start, int *fxele){

int i, p;

path[0] = closelist[j];
p = 1;

struct list tempsq;

tempsq.x = (*closelist).px[j];
tempsq.y = (*closelist).py[j];

while(tempsq.x=!start.x && tempsq.y =! start.y){

for(i = 0; i <= *fxele; i++){

if(closelist.x[i] = tempsq.x){

for(j = 0; j <= *fxele; j++){

if(closelist.y[j] = tempsq.y){

path[p] = closelist[j];
p = p+1;
tempsq.x = closelist.px[j];
tempsq.y = closelist.py[j];

}
}
}
}
}

return;
}

该代码旨在追溯寻路系统的方格的父级,但具体细节并不重要。我很好奇我调用“closelist”和“start”的方式有什么问题,这阻止了我调用它们的结构元素。

最佳答案

这些陈述

tempsq.x = (*closelist).px[j];
tempsq.y = (*closelist).py[j];

错了。
pxpy 不是结构中的数组。而是尝试这个

tempsq.x = closelist[j].px;
tempsq.y = closelist[j].py;

关于c - 访问函数中的结构元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20307013/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com