Skip to content

Instantly share code, notes, and snippets.

@promovicz
Created November 7, 2020 21:53
Show Gist options
  • Select an option

  • Save promovicz/5cfb091a6a77d8739b4e7dede27c9c28 to your computer and use it in GitHub Desktop.

Select an option

Save promovicz/5cfb091a6a77d8739b4e7dede27c9c28 to your computer and use it in GitHub Desktop.
Converting binary data into Unicode Braille
#include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
#include <unistd.h>
int main(int argc, char **argv) {
int res, i;
char buf[64];
setlocale(LC_CTYPE, "");
while(1) {
res = read(0, buf, sizeof(buf));
if(res == 0) {
break;
}
if(res == -1) {
if(errno == EAGAIN) {
continue;
} else {
perror("read");
return 1;
}
}
for(i = 0; i < res; i++) {
wchar_t w = 0x2800 + (buf[i] & 0xFF);
fputwc(w, stdout);
}
}
fflush(stdout);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment