|
diff --git a/example.c b/example.c
|
| ... |
| 2 |
#include <stdlib.h> |
2 |
#include <stdlib.h> |
| 3 |
|
3 |
|
| 4 |
typedef enum { |
4 |
typedef enum { |
| 5 |
STATUS_IDLE, |
5 |
STATUS_IDLE, |
| 6 |
STATUS_RUNNING, |
6 |
STATUS_RUNNING, |
| 7 |
STATUS_STOPPED |
7 |
STATUS_STOPPED |
| 8 |
} Status; |
8 |
} Status; |
| 9 |
|
9 |
|
| 10 |
typedef struct { |
10 |
typedef struct { |
| 11 |
int x; |
11 |
int x; |
| 12 |
int y; |
12 |
int y; |
| 13 |
} Point; |
13 |
} Point; |
| 14 |
|
14 |
|
| 15 |
typedef struct { |
15 |
typedef struct { |
| 16 |
Point top_left; |
16 |
Point top_left; |
| 17 |
Point bottom_right; |
17 |
Point bottom_right; |
| 18 |
} Rectangle; |
18 |
} Rectangle; |
| 19 |
|
19 |
|
| 20 |
typedef struct { |
20 |
typedef struct { |
| 21 |
int q; |
21 |
int q; |
| 22 |
int w; |
22 |
int w; |
| 23 |
} Bar; |
23 |
} Bar; |
| 24 |
|
24 |
|
| 25 |
int add_numbers(int a, int b) { |
25 |
int add_numbers(int a, int b) { |
| 26 |
int result = a + b; |
26 |
int result = a + b; |
| 27 |
return result; |
27 |
return result; |
| 28 |
} |
28 |
} |
| 29 |
|
29 |
|
| 30 |
int fibonacci(int n) { |
30 |
int fibonacci(int n) { |
| 31 |
if (n <= 1) return n; |
31 |
if (n <= 1) return n; |
| 32 |
return fibonacci(n - 1) + fibonacci(n - 2); |
32 |
return fibonacci(n - 1) + fibonacci(n - 2); |
| 33 |
} |
33 |
} |
| 34 |
|
34 |
|
| 35 |
void print_rectangle(Rectangle rect) { |
35 |
void print_rectangle(Rectangle rect) { |
| 36 |
printf("> Rect: (%d, %d) to (%d, %d)\n", |
36 |
printf("> Rect: (%d, %d) to (%d, %d)\n", |
| 37 |
rect.top_left.x, rect.top_left.y, |
37 |
rect.top_left.x, rect.top_left.y, |
| 38 |
rect.bottom_right.x, rect.bottom_right.y); |
38 |
rect.bottom_right.x, rect.bottom_right.y); |
| 39 |
} |
39 |
} |
| 40 |
|
40 |
|
| 41 |
int main(int argc, char **argv) { |
41 |
int main(int argc, char **argv) { |
| 42 |
const char *myenv = getenv("MYENV"); |
42 |
const char *myenv = getenv("MYENV"); |
| 43 |
|
43 |
|
| 44 |
int a = 100; |
44 |
char *args[3]; |
| 45 |
int b = 123; |
45 |
for (int i = 0; i < argc; i++) { |
| 46 |
int c = add_numbers(a, b); |
46 |
args[i] = argv[i]; |
|
|
47 |
} |
|
|
48 |
|
|
|
49 |
int a = 100; |
|
|
50 |
int b = 123; |
|
|
51 |
int c = add_numbers(a, b); |
| 47 |
|
52 |
|
| 48 |
Bar bar = { .q = 565, .w = 949 }; |
53 |
Bar bar = { .q = 565, .w = 949 }; |
| 49 |
Status status = STATUS_RUNNING; |
54 |
Status status = STATUS_RUNNING; |
| 50 |
|
55 |
|
| 51 |
Rectangle rect = { |
56 |
Rectangle rect = { |
| 52 |
.top_left = { .x = 10, .y = 20 }, |
57 |
.top_left = { .x = 10, .y = 20 }, |
| 53 |
.bottom_right = { .x = 50, .y = 80 } |
58 |
.bottom_right = { .x = 50, .y = 80 } |
| 54 |
}; |
59 |
}; |
| 55 |
|
60 |
|
| 56 |
printf("> MYENV: %s\n", myenv ? myenv : "NULL"); |
61 |
printf("> MYENV: %s\n", myenv ? myenv : "NULL"); |
| 57 |
printf("> c: %d (via add_numbers)\n", c); |
62 |
printf("> c: %d (via add_numbers)\n", c); |
| 58 |
printf("> bar.q: %d\n", bar.q); |
63 |
printf("> bar.q: %d\n", bar.q); |
| 59 |
printf("> status: %d\n", status); |
64 |
printf("> status: %d\n", status); |
| 60 |
|
65 |
|
| 61 |
print_rectangle(rect); |
66 |
print_rectangle(rect); |
| 62 |
|
67 |
|
| 63 |
int fib5 = fibonacci(5); |
68 |
int fib5 = fibonacci(5); |
| 64 |
printf("> fib(5): %d\n", fib5); |
69 |
printf("> fib(5): %d\n", fib5); |
| 65 |
|
70 |
|
| 66 |
int arr[] = {10, 20, 30, 40, 50}; |
71 |
int arr[] = {10, 20, 30, 40, 50}; |
| 67 |
int *ptr = arr; |
72 |
int *ptr = arr; |
| 68 |
for (int i = 0; i < 5; i++) { |
73 |
for (int i = 0; i < 5; i++) { |
| 69 |
printf("> arr[%d] = %d (via ptr: %d)\n", i, arr[i], *(ptr + i)); |
74 |
printf("> arr[%d] = %d (via ptr: %d)\n", i, arr[i], *(ptr + i)); |
| 70 |
} |
75 |
} |
| 71 |
|
76 |
|
| 72 |
for (int i = 0; i < 3; i++) { |
77 |
for (int i = 0; i < 3; i++) { |
| 73 |
printf("> loop %d\n", i); |
78 |
printf("> loop %d\n", i); |
| 74 |
} |
79 |
} |
| 75 |
|
80 |
|
| 76 |
return 0; |
81 |
return 0; |
| 77 |
} |
82 |
} |