-
-
Save morganwilde/9448399 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
struct Point { | |
int x; | |
int y; | |
int z; | |
}; | |
struct Segment { | |
struct Point *p1; | |
struct Point *p2; | |
}; | |
struct Segment *segment(struct Point *p1) { | |
// Create a new point symmetrical to 0yz | |
struct Point *p2 = malloc(sizeof(struct Point)); | |
p2->x = -p1->x; | |
p2->y = p1->y; | |
p2->z = p1->z; | |
// Create a segment | |
struct Segment *s = malloc(sizeof(struct Segment)); | |
s->p1 = p1; | |
s->p2 = p2; | |
return s; | |
} | |
int main(void) { | |
struct Point *p = malloc(sizeof(struct Point)); | |
p->x = 1; | |
p->y = 2; | |
p->z = 3; | |
struct Segment *s = segment(p); | |
printf("components\n"); | |
printf("p1: x=%d; y=%d; z=%d\n", s->p1->x, s->p1->y, s->p1->z); | |
printf("p2: x=%d; y=%d; z=%d\n", s->p2->x, s->p2->y, s->p2->z); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment