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

29th Sep 2020, 8:55 AM
Seb TheS
Seb TheS - avatar
4 Antworten
+ 1
Seb TheS char* p = ptr; Then do all of the things with p.
29th Sep 2020, 10:42 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 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.
29th Sep 2020, 9:19 AM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
CarrieForle Viceversa is better: char p[30000] = {0}; char* ptr = p; The problems seem to be fixed now, thanks a lot!
29th Sep 2020, 10:47 AM
Seb TheS
Seb TheS - avatar
0
@CarrieForle Typos are fixed, but I don't know what to do. Should I declare the array differently?
29th Sep 2020, 10:05 AM
Seb TheS
Seb TheS - avatar