debugging - Getting invalid operand to binary error in C Mandelbrot Program -


i'm supposed write program in c create mandelbrot. have specific instructions follow , i'm pretty sure have followed them correctly. question have when try compile code gcc (using make command) error says:

mason> make gcc -c main.c main.c: in function ‘main’: main.c:13:40: error: invalid operands binary < (have ‘complex_t’ , ‘int’) 

i have been having lot of issues complex_t in order make double mandelbrot print. if please see if can find error keep missing. here code files:

main.c (where error is):

#include <stdio.h> #include "complex.h" #include "mandelbrot.h"  int main (void)      {           complex_t c;              (c.imag = -1.2; c.imag < 2.8; c.imag+= 0.05)        {                  (c.real = -2.1; c.real < -0.66; c.real+= 0.032)                  {                     if (abs_complex(mandelbrot(15,c)) > 100)                     {                         printf("-");                     }                     else                         printf("#");                  }                  printf("\n");       }             return (0); } 

mandelbrot.c:

#include "complex.h" #include "mandelbrot.h"  complex_t mandelbrot(int n, complex_t c) {  complex_t m = {100,100}; complex_t tmp;      if (n == 0)     {         return c;     }      else      if (abs_complex(mandelbrot(n-1,c) > 1000))     {         return m;     }      else     {      tmp = mandelbrot(n-1,c);             tmp = cmult(tmp, tmp);     tmp = cadd(tmp,c);      }         return tmp; } 

mandelbrot.h:

complex_t mandelbrot(int n, complex_t c); 

complex.c:

#include <stdio.h> #include <math.h> #include "complex.h"   /*  *  complex number input function returns standard scanning error code  *    1 => valid scan, 0 => error, negative eof value => end of file  */ int scan_complex(complex_t *c) /* output - address of complex variable         fill     */ {       int status;        status = scanf("%lf%lf", &c->real, &c->imag);       if (status == 2)             status = 1;       else if (status != eof)             status = 0;        return (status); }  /*  *  complex output function displays value (a + bi) or (a - bi),  *  dropping or b if round 0 unless both round 0  */ void print_complex(complex_t c) /* input - complex number display   */ {       double a, b;       char   sign;        = c.real;       b = c.imag;        printf("(");        if (fabs(a) < .005  &&  fabs(b) < .005) {             printf("%.2f", 0.0);       } else if (fabs(b) < .005) {             printf("%.2f", a);       } else if (fabs(a) < .005) {             printf("%.2fi", b);       } else {             if (b < 0)                   sign = '-';             else                   sign = '+';             printf("%.2f %c %.2fi", a, sign, fabs(b));       }        printf(")"); }  /*  *  returns sum of complex values c1 , c2  */ complex_t add_complex(complex_t c1, complex_t c2) /* input - values add    */ {       complex_t csum;        csum.real = c1.real + c2.real;       csum.imag = c1.imag + c2.imag;        return (csum); }  /*  *  returns difference c1 - c2  */ complex_t subtract_complex(complex_t c1, complex_t c2) /* input parameters    */ {       complex_t cdiff;       cdiff.real = c1.real - c2.real;       cdiff.imag = c1.imag - c2.imag;        return (cdiff); }  /*  ** stub **  *  returns product of complex values c1 , c2  */ complex_t multiply_complex(complex_t c1, complex_t c2) /* input parameters    */ {       complex_t cmul;       double a, b, c, d;       = c1.real;       b = c1.imag;       c = c2.real;       d = c2.imag;        if (( b > 0 && d < 0) || (b < 0 && d > 0))       {           cmul.real - (a*c) + (fabs(b)*fabs(d));           cmul.imag = (a*d) + (b*c);       }       else if (( b>0 && d>0) || (b<0 && d<0))       {       cmul.real = (a*c) - (b*d);       cmul.imag = (a*d) + (b*c);   }       return (cmul); }  /*  ** stub **  *  returns quotient of complex values (c1 / c2)  */ complex_t divide_complex(complex_t c1, complex_t c2) /* input parameters     */ {       complex_t cdiv;       double a, b, c, d;       = c1.real;       b = c1.imag;       c = c2.real;       d = c2.imag;        if ( b > 0 && d < 0)       {           cdiv.real = (a*c) - (fabs(b)*fabs(d)) / ((c*c) + (d*d));           cdiv.imag = (a*d) + (b*c) / ((c*c) + (d*d));       }       else if ( b>0 && d>0)       {           cdiv.real = (a*c) - (fabs(b)*fabs(d)) / ((c*c) + (d*d));           cdiv.imag = ((-1*a*d) + (b*c)) / ((c*c) + (d*d));   }       else if (b<0 && d<0)   {          cdiv.real = (a*c) + (fabs(b)*fabs(d)) / ((c*c) + (d*d));          cdiv.imag = ((-1*a*d) + (b*c)) / ((c*c) + (d*d));   }   else if (b<0 && d<0)   {         cdiv.real = (a*c) + (fabs(b)*fabs(d)) / ((c*c) + (d*d));         cdiv.imag = ((a*fabs(d)) + (b*c)) / ((c*c) + (d*d));   }       return (cdiv); } /*  *  returns absolute value of complex number c  */ double abs_complex(complex_t c) /* input parameter                        */ {       complex_t cabs;        cabs.real = sqrt(c.real * c.real + c.imag * c.imag);        return (cabs.real); } 

complex.h:

typedef struct {       double real, imag; } complex_t;  int scan_complex(complex_t *c); void print_complex(complex_t c); complex_t add_complex(complex_t c1, complex_t c2); complex_t subtract_complex(complex_t c1, complex_t c2); complex_t multiply_complex(complex_t c1, complex_t c2); complex_t divide_complex(complex_t c1, complex_t c2); complex_t abs_complex(complex_t c); 

your header complex.h declares:

complex_t abs_complex(complex_t c); 

your implementation complex.c defines:

double abs_complex(complex_t c) { 

so what's happening code won't compile because abs_complex in header file saying returns complex_t , not double.

presumably complex.c doesn't compile because of mismatched definition/declaration.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -