1

Error descriptionAs 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));
}
5
  • 5
    What is the exact error message and on which line? Commented Apr 12, 2019 at 5:38
  • 1
    Please post textual information as text, not as picture of text. Commented Apr 12, 2019 at 5:45
  • 1
    I cannot see the pic. If it's text, do paste text as text, not as bitmap. Commented Apr 12, 2019 at 5:45
  • 1
    Thanks, although somebody has answered yet, and he managed to solve my problem so I won't edit it now. Commented Apr 12, 2019 at 5:47
  • do not use leading underscores, leading double underscores, and underscore followed by capital letter in names, Such is 'reserved' for the system Commented Apr 12, 2019 at 21:37

1 Answer 1

6

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 e.g

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 */
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.