我只在 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
不一样。
The.
具有更高的优先级,因此它的绑定比*
.
要使第一个版本工作,请执行以下操作:
(*(pri+i)).number
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句