Skip to content

Commit 23e715e

Browse files
authored
Add Baklava in Cyclone (#4262)
1 parent c182d04 commit 23e715e

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

archive/c/cyclone/baklava.cyc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
4+
int main() {
5+
char line[22];
6+
7+
// Tell compiler that pointer math is going to be done, and the result
8+
// may not be null terminated
9+
char *@fat @nozeroterm line_ptr = line;
10+
11+
for (int n = -10; n <= 10; n++) {
12+
int num_spaces = (n >= 0) ? n : -n;
13+
int num_stars = 21 - 2 * num_spaces;
14+
15+
// Write num_spaces " " to line
16+
memset(line_ptr, ' ', num_spaces);
17+
18+
// Append num_stars "*" to line
19+
memset(&line_ptr[num_spaces], '*', num_stars);
20+
21+
// Null terminate line
22+
line_ptr[num_spaces + num_stars] = '\0';
23+
24+
printf("%s\n", line);
25+
}
26+
27+
return 0;
28+
}

0 commit comments

Comments
 (0)