/*  Just to demonstrate struct usage in C, 
 *  not necessarily a recommendation.
 *  Author:  Yotam Medini  yotam.medini@gmail.com -- Created: 2007/June/06
 */

#include <stdio.h>
#include <stdlib.h>

struct Point {
    int  x;
    int  y;
};

struct ParllelRectangle {
    /* By any diagonal points, any order, SW-NE, NE-SW, SE-NW, NW-SE */
    struct Point  p1;
    struct Point  p2;
};

void show_point(const char* name, const struct Point* ppt) 
{
    printf("%s = (%d,%d)\n", name, (*ppt).x, (*ppt).y);
}


void show_rectangle(const char* name, const struct ParllelRectangle* rect) 
{
    printf("%s = (%d,%d)<->(%d,%d)\n", 
           name, (*rect).p1.x, (*rect).p1.y, (*rect).p2.x, (*rect).p2.y); 
}


int main(int argc, char** argv)
{
    /* Need to check argc, and possibly give Usage message, but I am lazy */

    static const char* pt_names[4] = { 
        "Point-A", "Point-B", "Point-C", "Point-D"
    };

    int  ai , pi;
    struct Point             points[4];
    struct ParllelRectangle  rect1, rect2;

    for (ai = 1, pi = 0;  pi < 4;  ++pi, ai += 2) {
        points[pi].x = atoi(argv[ai]);
        points[pi].y = atoi(argv[ai+1]);
    }

    for (pi = 0;  pi < 4;  ++pi) {
        show_point(pt_names[pi], &points[pi]);
    }

    rect1.p1 = points[0];
    rect1.p2 = points[1];
    rect2.p1 = points[2];
    rect2.p2 = points[3];

    show_rectangle("Rect1", &rect1);
    show_rectangle("Rect2", &rect2);

    return 0;
} /* main */




    

