Advertisement
image28

brainfuck2c

Dec 3rd, 2022 (edited)
945
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. #define P(C,X)case C:printf(#X);break; /* bftoc.c by markvipixar.com */
  5. int main(int argc, char *argv[])
  6. {
  7.     int c;
  8.     FILE *input;
  9.     char inbyte;
  10.     int tabs=0;
  11.     int d=0;
  12.    
  13.     if ( ( input=fopen(argv[1],"r") ) == NULL ) exit(-1);
  14.  
  15.     printf ("main(){\n\tchar *p;\n\tp=malloc(9999);\n");
  16.     while (!feof(input))
  17.     {
  18.         fread(&inbyte,1,1,input);
  19.         c=inbyte;
  20.        
  21.         if ( c == 91 )
  22.             tabs++;
  23.         else if ( c == 93 )
  24.             tabs--;
  25.  
  26.         for (d=0; d < tabs; d++)
  27.             printf("\t");
  28.  
  29.         switch(c)
  30.         {
  31.             P(62, \t*(p)++;\n);
  32.             P(60, \t*(p)--;\n);
  33.             P(43, \t++*(p);\n);
  34.             P(45, \t--*(p);\n);
  35.             P(46, \tputchar(*p);\n);
  36.             P(44, \t*p=getchar();\n);
  37.             P(91, while (*p){\n);
  38.             P(93, \t}\n);
  39.            
  40.         }
  41.     }
  42.     printf("\texit(0);\n}\n");
  43.     fclose(input);
  44.  
  45.     exit(0);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement