I’m having some trouble getting my program to compile and I think the majority of the problem now is that I’ve been looking at it for too long…
Overview of this one part of the program: you have a complex number in rectangular form (represented by the structure “Complex”) that you want to convert to a complex number in polar form (represented by the structure “pComplex”)
Upon trying to build, I’m getting these errors, each three times:
"error C2059: syntax error: ')'"
"error C2059: syntax error: ';'"
"error C2061: syntax error: identifier 'c1'"
"error C2146: syntax error: missing ')' before identifier 'c1'"
Also, I receive IntelliSense: identifier "Complex" is undefined but only until click on the line in question, then it goes away.
All errors point to the same line of the same header file (pcomplex.h):
pComplex NF_convert_c2_pcdouble(Complex c1);
relevant parts of pcomplex.h:
#ifndef PCOMPLEX_H
#define PCOMPLEX_H
#include "complex.h"
#include <math.h>
//
// ...
//
typedef struct nf_complex_polar{
double r;
double angle;
} pComplex;
//
// ...
//
pComplex NF_convert_c2_pcdouble(Complex c1);
//
// ...
//
#endif
relevant parts of complex.h:
#ifndef COMPLEX_H
#define COMPLEX_H
#include "pcomplex.h"
#include <math.h>
//
// ...
//
typedef struct nf_complex{
double real;
double imag;
} Complex;
//
// ...
//
Complex NF_convert_pc2_cdouble(pComplex pc1);
//
// ...
//
#endif
Something else I’ve noticed, when I hover over the function name in pcomplex.c,
pComplex NF_convert_c2_pcdouble(Complex c1)
{
//This function converts a rectangular form complex number c1
// and returns it as a polar form complex number pc1
pComplex pc1;
double x, y, r, a;
x = c1.real;
y = c1.imag;
r = sqrt( x*x + y*y );
a = atan2(y,x);
pc1.r = r;
pc1.angle = a;
return pc1;
}
I get a little popup box containing this, and I don’t know what the second line means:
pComplex NF_convert_c2_pcdouble(Complex c1)
pComplex NF_convert_c2_pcdouble(<error-type> c1)
Is this enough information and code to merit asking for help in figuring this out? The two header files are about 100 lines each, and the corresponding source files are about 1000 lines…so I tried to keep it relevant.
Are you coding in C or in C++ ? If coding in C++, defining your class-es should be better style.
Having both
pcomplex.handcomplex.hinclude each other is a poor design. The inclusion graph should be a DAG.I suggest merging the two headers into one single header having both
CartesianComplexandPolarComplextypes.(I guess your teacher don’t want you to use the standard headers defining complex numbers)