puzzles/ascii-table/ascii_table.c
Zoé Cassiopée Gauthier 7e4f02547b Initial commit
2024-04-02 17:01:09 -04:00

41 lines
644 B
C

#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
char randascii() {
while (true) {
char r = rand() & 0x7f;
if (r >= 0x20 && r <= 0x7e) {
return r;
}
}
}
int main(int argc, char **argv) {
char last = 0x1f;
int skips = 0;
int line_len = 0;
while (true) {
char c = randascii();
putchar(c);
if (c == last + 1 && skips++ == 10) {
last = c;
if (line_len++ == 15) {
putchar('\n');
line_len = 0;
}
if (c == 0x7e) {
break;
}
skips = 0;
} else {
putchar('\b');
}
usleep(200);
}
putchar('\n');
}