aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--brainfuck/brainfuck/main.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/brainfuck/brainfuck/main.cpp b/brainfuck/brainfuck/main.cpp
index b1e0afa..669ab0a 100644
--- a/brainfuck/brainfuck/main.cpp
+++ b/brainfuck/brainfuck/main.cpp
@@ -40,9 +40,10 @@ void init()
40 break; 40 break;
41 else 41 else
42 { 42 {
43 one.command[one.count++] = c; 43 one.command[++one.count] = c;
44 } 44 }
45 } 45 }
46 one.command[one.count] = '\0';
46} 47}
47 48
48void run() 49void run()
@@ -50,7 +51,7 @@ void run()
50 char c; 51 char c;
51 int i; 52 int i;
52 53
53 while (c = one.command[one.pos++]) 54 while (c = one.command[++one.pos])
54 { 55 {
55 switch (c) 56 switch (c)
56 { 57 {
@@ -67,17 +68,17 @@ void run()
67 one.ptr--; 68 one.ptr--;
68 break; 69 break;
69 case ',': 70 case ',':
70 71 *one.ptr = getchar();
71 break; 72 break;
72 case '.': 73 case '.':
73 putchar(*one.ptr); 74 putchar(*one.ptr);
74 break; 75 break;
75 case '[': 76 case '[':
76 if (*one.ptr) 77 if (*one.ptr != 0)
77 break; 78 break;
78 else 79 else
79 { 80 {
80 for (i = one.pos; i < one.count; i++) 81 for (i = one.pos + 1; i <= one.count; i++)
81 { 82 {
82 if (one.command[i] == ']') 83 if (one.command[i] == ']')
83 { 84 {
@@ -88,11 +89,11 @@ void run()
88 } 89 }
89 break; 90 break;
90 case ']': 91 case ']':
91 if (*one.ptr) 92 if (*one.ptr == 0)
92 break; 93 break;
93 else 94 else
94 { 95 {
95 for (i = one.pos; i >= 0; i--) 96 for (i = one.pos - 1; i >= 1; i--)
96 { 97 {
97 if (one.command[i] == '[') 98 if (one.command[i] == '[')
98 { 99 {
Powered by cgit v1.2.3 (git 2.41.0)