+ 12

Help Me in this code! Why is it not working?

I have tried to make a simple brainf*** interpreter to take code and output its result... But it is not working and giving any output... Please Help!

16th Apr 2017, 6:42 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
9 Answers
+ 15
0) Where did you get this code 1) Where did you try to run it on 2) What errors did you get
16th Apr 2017, 6:49 AM
Hatsy Rei
Hatsy Rei - avatar
+ 13
@Hatsy 0) Made it myself 1) Ran it on CppDroid 2) No Errors, but no output on input: +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++. //Should Print 'A' Or this: ++++++++[>+++++++++<-]>+.<++++++[>------<-]>-----.<++++++[>+++++++<-]>++.<+++++[>+++++++<-]>.+++++++.-----------------.<++++++++[>--------<-]>-----.<+++++++[>++++++++<-]>+.<++++[>+++++<-]>++.++++++.
16th Apr 2017, 6:52 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 12
@Hatsy Rei On running this in Code Playground, the compiler gives me a Compilation Error, which I am unable to find...
16th Apr 2017, 7:30 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 12
@Babak Sheykhan (PERS) Yes...
16th Apr 2017, 7:37 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 12
@Ace Can you please name one, sir? The truth is that I have never used an online debugger... 😅
29th Apr 2017, 9:02 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 12
@Ace But what you meant was an automatic one, right sir? Or you wanted me myself to find the errors - that I tried but couldn't find any...(Perhaps I don't have that much knowledge)...
29th Apr 2017, 9:36 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 12
@Ace Thank You, Sir!
29th Apr 2017, 9:41 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 11
#include <iostream> using namespace std; class Brainfuck {   public:     char data[30000];     char *d;     const char *p;     Brainfuck(const char prog[]) {       d = data;       p = prog;     }     void pincr() {       d++;     }     void pdecr() {       d--;     }     void vincr() {       (*d)++;     }     void vdecr() {       (*d)--;     }     void puts() {       cout << *d;     }     void gets() {       cin >> *d;     }     void bropen() {       int bal = 1;       if (*d == '\0') {         do {           p++;           if (*p == '[') bal++;           else if (*p == ']') bal--;         } while ( bal != 0 );       }     }     void brclose() {       int bal = 0;       do {         if (*p == '[') bal++;         else if (*p == ']') bal--;      p--;       } while ( bal != 0 );     }     void evaluate() {       while (*p) {         switch (*p) {           case '>':             pincr();             break;           case '<':             pdecr();             break;           case '+':             vincr();             break;           case '-':             vdecr();             break;           case '.':             puts();             break;           case ',':             gets();             break;           case '[':             bropen();             break;           case ']':             brclose();             break;         }         p++;       }     } ; int main(void) {   char* buffer; buffer= new char [10000]; cin>>buffer;   Brainfuck interpreter(buffer);   interpreter.evaluate(); }
16th Apr 2017, 6:43 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 4
Did you trace your code?
16th Apr 2017, 7:34 AM
Babak
Babak - avatar