Código
#include <stdio.h> #include <stdlib.h> void Brainfuck(char *pcData, unsigned long dwData, unsigned char *ucStack, unsigned long dwStack, unsigned long *dwStackPtr); int main() { char ucData[] = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."; unsigned long dwStackPtr = 0; unsigned long dwStack = 16384; Brainfuck(ucData, sizeof(ucData) - 1, pvStack, dwStack, &dwStackPtr); return 0; } void Brainfuck(char *pcData, unsigned long dwData, unsigned char *ucStack, unsigned long dwStack, unsigned long *dwStackPtr) { if(!pcData || !dwData || !ucStack || !dwStack || !dwStackPtr) {return;} unsigned long i; for(i = 0; i < dwData; i++) { switch(pcData[i]) { case '>': if(*dwStackPtr < dwStack) {(*dwStackPtr)++;} break; case '<': if(*dwStackPtr) {(*dwStackPtr)--;} break; case '+': ucStack[*dwStackPtr]++; break; case '-': ucStack[*dwStackPtr]--; break; case '[': { unsigned long j = 0; int iLoop = 0; do { if(pcData[i + j] == '[') {iLoop++;} else if(pcData[i + j] == ']') {iLoop--;} j++; } while((j < dwData - i) && iLoop); while(ucStack[(*dwStackPtr)]) {Brainfuck(&pcData[i + 1], j - 1, ucStack, dwStack, dwStackPtr);} i += j; break; } } } }