Advertisement
slaanani

brainfuck dial zeb

Jul 20th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <io.h>
  2. #include <stdlib.h>
  3.  
  4. int main(int argc, char **argv)
  5. {
  6. char tab[2048] = {0};
  7. char *ptr;
  8. int lc;
  9. int i = 0;
  10.  
  11. ptr = tab;
  12.  
  13. if (argc == 2)
  14. {
  15. while (argv[1][i])
  16. {
  17. if (argv[1][i] == '>')
  18. ptr++;
  19. else if (argv[1][i] == '<')
  20. ptr--;
  21. else if (argv[1][i] == '+')
  22. (*ptr)++;
  23. else if (argv[1][i] == '-')
  24. (*ptr)--;
  25. else if (argv[1][i] == '.')
  26. _write(1, &(*ptr), 1);
  27. else if (argv[1][i] == '[' && *ptr == 0)
  28. {
  29. lc = 1;
  30. while (lc != 0)
  31. {
  32. if (argv[1][i] =='[')
  33. lc++;
  34. if (argv[1][i] == ']')
  35. lc--;
  36. i++;
  37. }
  38. }
  39. else if (argv[1][i] == ']' && *ptr != 0)
  40. {
  41. lc = 1;
  42. while (lc != 0)
  43. {
  44. if (argv[1][i] =='[')
  45. lc--;
  46. if (argv[1][i] == ']')
  47. lc++;
  48. i--;
  49. }
  50. }
  51. i++;
  52. }
  53. }
  54. else
  55. _write(1, "\n", 1);
  56. return (0);
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement