-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetastruct.cpp
53 lines (43 loc) · 945 Bytes
/
metastruct.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/* Struct inside a struct
* Tanner Babcock
* tababcock@dmacc.edu
* September 30, 2021 */
#include <iostream>
typedef struct Point {
int x;
int y;
} Point_t;
typedef struct Line {
struct Point start;
struct Point end;
} Line_t;
typedef struct Rectangle {
struct Point topLeft;
struct Point topRight;
struct Point bottomLeft;
struct Point bottomRight;
} Rectangle_t;
void printLine(Line_t *l) {
std::cout << "Line starts at (" << l->start.x << "," << l->start.y << ")";
std::cout << " and ends at (" << l->end.x << "," << l->end.y << ")" << std::endl;
}
Line_t crossLine(Line_t *l) {
int sx = l->start.y;
int sy = l->start.x;
int ex = l->end.y;
int ey = l->end.x;
return {
.start = { .x = sx, .y = sy },
.end = { .x = ex, .y = ey }
};
}
int main(void) {
Line_t line = {
.start = { .x = 5, .y = 12 },
.end = { .x = 20, .y = 40 }
};
printLine(&line);
line = crossLine(&line);
printLine(&line);
return 0;
}