c - Struct Definition on Include Not Recognized -


it must way professor declared typedefs, because haven't run problem yet.

i have following (piece) of header file, , accompanying code 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 no terms in polynomial...");      while (p != null) {          // print 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 sign of next term, if applies         if (p.next != null) {             if (p.next->coef > 0) printf(" + ");             else printf(" - ");         }     } } 

but following every time try access property of struct:

error: request member 'exp' in not structure or union

the includes, definitions , there -- did similar in c structs , typedefs, didn't use syntax: typedef term * polynomial;. guess might causing problem, , throwing me off.

if can't access members of struct p.exp, p.coef, , p.next, how can i?

ps - typedef term * polynomial; do/mean? imagine "multiple terms make single polynomial" don't understand how access terms changes.

polynomial typedefed pointer term. cannot use . access elements. have either dereference first:

(*p).next 

or use arrow operator:

p->next 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -