[英]Conflicting types error while passing pointer to the string as argument to function
As I wrote in subject, I am getting conflicting types error when I try to pass pointer to the struct, delcared using array of structs. 正如我在主题中所写的那样,当我尝试将指针传递给使用结构数组替代的结构时,我遇到了冲突类型错误。 Have you got any suggestions to remove this error? 您是否有删除此错误的建议? What I am missing? 我缺少什么?
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define N 10
void count_length(struct abc *_el);
struct vector {
double x;
double y;
};
struct abc {
struct vector vec;
double length;
};
int main(void)
{
struct abc set[N];
srand(time(NULL));
for(int i=0; i<N; i++)
{
set[i].vec.x = rand();
set[i].vec.y = rand();
count_length(&set[i]);
}
}
void count_length(struct abc *_el)
{
for(int i=0; i<N; i++)
_el->length = sqrt(pow(_el->vec.x, 2.0) + pow(_el->vec.y, 2.0));
}
Keep the function declaration 保留函数声明
void count_length(struct abc *_el); /* compiler don't knows what is struct abc as you have defined it after this statement */
after structure not before. 之后的结构不是之前的。 for eg 例如
struct vector {
double x;
double y;
};
struct abc {
struct vector vec;
double length;
};
void count_length(struct abc *_el); /* here compiler knows what is struct abc */
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.