It must be the way my professor declared the typedef
s, because I haven't run into this problem yet.
I have the following (piece) of a header file, and the accompanying code that uses it:
polynomial.h -
#ifndef POLYNOMIAL_H_
#define POLYNOMIAL_H_
struct term {
int coef;
int exp;
struct term *next;
};
typedef struct term term;
typedef term * polynomial;
#endif
polynomial.c -
#include "polynomial.h"
void display(polynomial p)
{
if (p == NULL) printf("There are no terms in the polynomial...");
while (p != NULL) {
// Print the term
if (p.exp > 1) printf(abs(p.coef) + "x^" + p.exp);
else if (p.exp == 1) printf(abs(p.coef) + "x");
else printf(p.coef);
// Print the sign of the next term, if it applies
if (p.next != NULL) {
if (p.next->coef > 0) printf(" + ");
else printf(" - ");
}
}
}
But I get the following for every time I try to access any property of the struct:
error: request for member 'exp' in something not a structure or union
The includes, definitions and all that are there -- I just did something similar in C with structs and typedefs, but I didn't use this syntax: typedef term * polynomial;
. I guess this might be causing the problem, and throwing me off.
If I can't access the members of the struct as p.exp
, p.coef
, and p.next
, how can I?
PS - Exactly what does typedef term * polynomial;
do/mean? I imagine that "multiple terms make up a single polynomial" but I don't understand how access to term
s changes.