Add to the previous program by defining a function that initializes a triangle.
/* declare the Point type */ /* declare the Color type */ /* declare the Triangle type */ /* function to print a Point */ void printPoint( Point *p ) {...} /* function to print a Color */ void printColor( Color *c ) {...} /* function to print a Triangle */ void printTriangle( Triangle *t ) {...} /* function to initialize a Triangle */ void setTriangle( Triangle *t, Point p0, Point p1, Point p2, Color c ) {...} int main() { /* declare and initialize three Points and a Color */ Point p0={-32,77}, p1={345, 490}, p2={140, 389}; Color c={230, 120, 54}; /* declare and initialize a Triangle */ Triangle tri; setTriangle( &tri, p0, p1, p2, c ); /* print the Triangle */ printTriangle( &tri); return 0; }
The triangle constructor uses a mix of arguments: some are addresses and others are copies of other structs.