0
Why doesn't this translation work? (Brainfart to C)
Hello. I wanted to make a compiler for brainfart, which simply converts brainfart's symbols to the equivalent C statements, like in the map from Brainfart's Wikipedia page: brainfart command C equivalent (Program Start) char ptr[30000] = {0}; > ++ptr; < --ptr; + ++*ptr; - --*ptr; . putchar(*ptr); , *ptr=getchar(); [ while (*ptr) { ] } I tried with ++++++++[>++++++++<-]>+. which is supposed to print character A, but the C program equivalent runs in errors, which will seem to be weighted on ++ptr; and --ptr; statements. Why do the errors appear? C-equivalent: https://code.sololearn.com/cH7AJF3KGzSX/#c
4 Antworten
+ 1
Seb TheS
char* p = ptr;
Then do all of the things with p.
+ 1
Array can convert to a pointer, BUT it itself "is not" a pointer. It's a container.
++ and -- cannot be applied to an array. You need to declare a pointer which points to the array.
Also putchar() typo.
+ 1
CarrieForle Viceversa is better:
char p[30000] = {0};
char* ptr = p;
The problems seem to be fixed now, thanks a lot!
0
@CarrieForle Typos are fixed, but I don't know what to do. Should I declare the array differently?