'Segment(aka Struct Segment) has no member named v (or w)

I am getting this error on the last printf line, however the v & w members have already been declared before, it normally should work:

#include <stdio.h>
struct Point {
float x;
float y;
float z;
};
typedef struct Point Point;

    struct Segment{
    Point a;
    Point b;
    };
    typedef struct Segment Segment;


int main(){
Point v = {4.1,6.2,9.3}, w= {3.3,6.6,9.9};
    Segment s;
    s.a = v;
    s.b = w;
printf("(%.1f, %.1f , %.1f) --- (%.1f , %.1f , %.1f)", s.v.x, s.v.y, s.v.z, s.w.x, s.w.y, s.w.z);
return 0;
}

It's been hurting my head for about 45 minutes now ._.

c


Solution 1:[1]

The type Segment has two members a and b and you would print them like this:

printf("(%.1f, %.1f , %.1f) --- (%.1f , %.1f , %.1f)",
   s.a.x, s.a.y, s.a.z,
   s.b.x, s.b.y, s.b.z);

This is how you would print the variables v and w:

printf("(%.1f, %.1f , %.1f) --- (%.1f , %.1f , %.1f)",
   v.x, v.y, v.z,
   w.x, w.y, w.z);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1