point-example.c

/* struct example - points
|       2020-09-29
*/
#include <stdio.h>
#include <math.h>       // sqrt()

struct Point {
    double x, y, z;
    double weight;
} ;

double length (struct Point *p)
{
    return sqrt( (*p).x * (*p).x  +  (*p).y * (*p).y  +  (*p).z * (*p).z );
}

int main(int argc, char **argv)
{
    struct Point    mypoints[10] ;      // array of 10 Points
    struct Point   *p;

    for (p = &(mypoints[0]);  p < &(mypoints[10]); p++) {
        printf("x, y, z, weight? ");
        scanf(" %lf %lf %lf %lf",
            &((*p).x),  &((*p).y),  &((*p).z),  &((*p).weight)
        );
    }

    for (p = &(mypoints[0]);  p < &(mypoints[10]); p++) {
        printf("point (%.2lf, %.2lf, %.2lf) has length %lf\n",
            (*p).x,  (*p).y,  (*p).z,  length(p)
        );
    }

    return 0;
}