aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJinweiClarkChao <[email protected]>2015-01-09 21:49:46 +0800
committerJinweiClarkChao <[email protected]>2015-01-09 21:49:46 +0800
commit6fa3e83d8ab020d5cf8c44cc097d6ac9f79f03fb (patch)
tree71050f920ff0fda3d7d8cedab019214edfda24d1
parent0526e79812cf242e12d5b8f4779f067bd8741668 (diff)
downloadbrainfuck-6fa3e83d8ab020d5cf8c44cc097d6ac9f79f03fb.tar.gz
fix
-rw-r--r--README.md20
-rw-r--r--add.bf1
-rw-r--r--brainfuck.c12
3 files changed, 5 insertions, 28 deletions
diff --git a/README.md b/README.md
index f1f0c80..8e79428 100644
--- a/README.md
+++ b/README.md
@@ -4,23 +4,5 @@ brainfuck
4##Usage: 4##Usage:
5```bash 5```bash
6gcc brainfuck.c -o brainfuck 6gcc brainfuck.c -o brainfuck
7./brainfuck HelloWorld.bf 7./brainfuck
8``` 8```
9
10##What's brainfuck
11Brainfuck is represented by an array with 30,000 cells initialized to zero
12and a data pointer pointing at the current cell.
13
14There are eight commands:
15```
16+ : Increments the value at the current cell by one.
17- : Decrements the value at the current cell by one.
18> : Moves the data pointer to the next cell (cell on the right).
19< : Moves the data pointer to the previous cell (cell on the left).
20. : Prints the ASCII value at the current cell (i.e. 65 = 'A').
21, : Reads a single input character into the current cell.
22[ : If the value at the current cell is zero, skips to the corresponding ] .
23 Otherwise, move to the next instruction.
24] : If the value at the current cell is zero, move to the next instruction.
25 Otherwise, move backwards in the instructions to the corresponding [ .
26``` \ No newline at end of file
diff --git a/add.bf b/add.bf
new file mode 100644
index 0000000..3d01081
--- /dev/null
+++ b/add.bf
@@ -0,0 +1 @@
,>++++++[<-------->-],,[<+>-],<.>. \ No newline at end of file
diff --git a/brainfuck.c b/brainfuck.c
index 8e80d07..ceb52c4 100644
--- a/brainfuck.c
+++ b/brainfuck.c
@@ -1,5 +1,4 @@
1#include <stdio.h> 1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h> 2#include <string.h>
4 3
5#define MAX_DATA 30000 4#define MAX_DATA 30000
@@ -19,15 +18,12 @@ void init()
19 memset(&one, 0, sizeof(one)); 18 memset(&one, 0, sizeof(one));
20 one.count = 0; 19 one.count = 0;
21 one.ptr = one.data; 20 one.ptr = one.data;
22 21
23 while ((c = getchar()) != EOF) 22 while ((c = getchar()) != EOF)
24 { 23 {
25 if (c == '\n') 24 if (c == '\n')
26 break; 25 break;
27 else 26 one.command[++one.count] = c;
28 {
29 one.command[++one.count] = c;
30 }
31 } 27 }
32 one.command[0] = one.count; 28 one.command[0] = one.count;
33 one.command[one.count] = '\0'; 29 one.command[one.count] = '\0';
@@ -97,9 +93,7 @@ void run()
97 93
98int main(int argc, char **argv) 94int main(int argc, char **argv)
99{ 95{
100 if (argc > 1) { 96 printf("Input the brainfuck expression below\n");
101 freopen(argv[1], "r", stdin);
102 }
103 init(); 97 init();
104 run(); 98 run();
105 return 0; 99 return 0;
Powered by cgit v1.2.3 (git 2.41.0)