-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructs.c
More file actions
52 lines (41 loc) · 828 Bytes
/
structs.c
File metadata and controls
52 lines (41 loc) · 828 Bytes
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
#include <stdio.h>
#define XMAX 200
#define YMAX 150
struct point makepoint(int, int, int, int, int);
struct point {
int x;
int y;
int z;
int a;
int b;
};
struct rect {
struct point pt1;
struct point pt2;
};
int main()
{
struct rect screen;
struct point middle;
screen.pt1 = makepoint(1, 2, 3, 4, 5);
screen.pt2 = makepoint(XMAX, YMAX, 4, 5, 6);
middle = makepoint((screen.pt1.x + screen.pt2.x)/2,
(screen.pt1.y + screen.pt2.y)/2, 0, 0, 0);
printf("midpoint: (%d,%d)\n", middle.x, middle.y);
struct point origin, *pp;
pp = &origin;
int a = (*pp).x;
a = pp->x;
return 0;
}
/* makepoint: make a point from x and y components */
struct point makepoint(int x, int y, int z, int a, int b)
{
struct point temp;
temp.x = x;
temp.y = y;
temp.z = z;
temp.a = a;
temp.b = b;
return temp;
}