gpt4 book ai didi

c - 仅在 eclipse 中出现此错误 "not a structure or union"

转载 作者:行者123 更新时间:2023-11-30 19:01:50 25 4
gpt4 key购买 nike

我只在 Eclipse 中收到此错误。我的代码在其他编译器中运行没有任何错误
这是我在 ECLIPSE 中遇到的错误

 21:20:16 **** Incremental Build of configuration Debug for project Sieve of Eratosthenes ****
Info: Internal Builder is used for build
gcc -O0 -g3 -Wall -c -fmessage-length=0 -o "src\\Sieve of Eratosthenes.o" "..\\src\\Sieve of Eratosthenes.c"
..\src\Sieve of Eratosthenes.c: In function 'main':
..\src\Sieve of Eratosthenes.c:16:15: error: request for member 'number' in something not a structure or union
*(pri+(i-2)).number=i;
^
..\src\Sieve of Eratosthenes.c:17:15: error: request for member 'value' in something not a structure or union
*(pri+(i-2)).value =1;
^
..\src\Sieve of Eratosthenes.c:20:23: error: request for member 'number' in something not a structure or union
printf("%d",*(pri+i).number);
^
..\src\Sieve of Eratosthenes.c:21:23: error: request for member 'value' in something not a structure or union
printf("%d",*(pri+i).value);
^

21:20:16 Build Failed. 4 errors, 0 warnings. (took 107ms)

我尝试在“https://www.onlinegdb.com/online_c_compiler”中运行我的代码,效果很好

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

struct prime {

int number;
int value;
};

int main() {
int n;
printf("enter range");
scanf("%d",&n);
struct prime pri[n-2];
for(int i=2;i<=n;i++){
pri[i-2].number=i;
pri[i-2].value =1;
}
for(int i=0 ;i<=n-2;i++){
printf("%d ",pri[i].number);
}

}

最佳答案

您面临的问题与 Eclipse 无关,而是与您在不同平台上使用的代码似乎不同这一事实有关。

*(pri+i).number

pri[i].number

不一样。

. 具有更高的 precedence ,因此它比 * 结合得更紧。

要使第一个版本起作用:

(*(pri+i)).number

关于c - 仅在 eclipse 中出现此错误 "not a structure or union",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57134918/

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