]> wirehaze git hosting - lifeboot.git/commitdiff

wirehaze git hosting

add grid
authorphfr24 <phfr24@inf.ufpr.br>
Sat, 25 Oct 2025 23:57:26 +0000 (20:57 -0300)
committerphfr24 <phfr24@inf.ufpr.br>
Sat, 25 Oct 2025 23:57:26 +0000 (20:57 -0300)
.gitignore
prototype.c [new file with mode: 0644]

index 8c99bf7468bf711ec091150279474b250123c526..6e7cfddd48ab97fd23f757bb53696830a7334536 100644 (file)
@@ -2,3 +2,4 @@
 **/*.bin
 **/*.o
 **/a.out
+prototype
diff --git a/prototype.c b/prototype.c
new file mode 100644 (file)
index 0000000..c0dd987
--- /dev/null
@@ -0,0 +1,32 @@
+#include <stdio.h>
+
+#define COLS 80
+#define ROWS 25
+
+#define DEAD ' '
+#define ALIVE '#'
+
+#define STR(x) _STR(x)
+#define _STR(x) #x
+
+char grid[COLS * ROWS] = { [0 ... (COLS*ROWS-1)] = ALIVE };
+
+static void print_row(char row[COLS]) {
+  printf("%." STR(COLS) "s\n", row);
+}
+
+static void print_grid(char grid[COLS * ROWS]) {
+  for (int i = 0; i < ROWS; i++)
+    print_row(grid + i * COLS);
+}
+
+static void clearscr() {
+  printf("\e[1;1H\e[2J");
+}
+
+int main () {
+  clearscr();
+  print_grid(grid);
+
+  return 0;
+}