Commit 7ea2c9a3 authored by xingqiao's avatar xingqiao
Browse files

helloworld basic code files

parent f5511b11
#include <stdlib.h>
#include <stdio.h>
#define N_TRITS 243
char *trit_encodings[N_TRITS];
......@@ -7,15 +8,29 @@ int main(void) {
// at the very beginning of your program, making the table
for (int i = 0; i < N_TRITS; i++) {
trit_encodings[i] = calloc(sizeof(char), 6);
int n=i;
for (int j = 0; j < 5; j++) {
int mod =n%3;
if (mod == 0)
trit_encodings[i][j]=' ';
else if (mod == 1)
trit_encodings[i][j]=':';
else
trit_encodings[i][j]='@';
n /= 3;
}
}
FILE *f = fopen("img.bin", "rb");
for (int i=0; i<40; i++) {
for (int j=0; j<18; j++) {
int c = fgetc(f);
if (c >= 0) {
printf("%s", trit_encodings[c]); // use %s with printf to print strings
}
}
printf("\n");
}
// at the very end of your program, cleaning up memory
for (int i = 0; i < N_TRITS; i++) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment