From 6fa3e83d8ab020d5cf8c44cc097d6ac9f79f03fb Mon Sep 17 00:00:00 2001 From: JinweiClarkChao Date: Fri, 9 Jan 2015 21:49:46 +0800 Subject: fix --- README.md | 20 +------------------- add.bf | 1 + brainfuck.c | 12 +++--------- 3 files changed, 5 insertions(+), 28 deletions(-) create mode 100644 add.bf diff --git a/README.md b/README.md index f1f0c80..8e79428 100644 --- a/README.md +++ b/README.md @@ -4,23 +4,5 @@ brainfuck ##Usage: ```bash gcc brainfuck.c -o brainfuck -./brainfuck HelloWorld.bf +./brainfuck ``` - -##What's brainfuck -Brainfuck is represented by an array with 30,000 cells initialized to zero -and a data pointer pointing at the current cell. - -There are eight commands: -``` -+ : Increments the value at the current cell by one. -- : Decrements the value at the current cell by one. -> : Moves the data pointer to the next cell (cell on the right). -< : Moves the data pointer to the previous cell (cell on the left). -. : Prints the ASCII value at the current cell (i.e. 65 = 'A'). -, : Reads a single input character into the current cell. -[ : If the value at the current cell is zero, skips to the corresponding ] . - Otherwise, move to the next instruction. -] : If the value at the current cell is zero, move to the next instruction. - Otherwise, move backwards in the instructions to the corresponding [ . -``` \ 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 @@ #include -#include #include #define MAX_DATA 30000 @@ -19,15 +18,12 @@ void init() memset(&one, 0, sizeof(one)); one.count = 0; one.ptr = one.data; - + while ((c = getchar()) != EOF) { if (c == '\n') break; - else - { - one.command[++one.count] = c; - } + one.command[++one.count] = c; } one.command[0] = one.count; one.command[one.count] = '\0'; @@ -97,9 +93,7 @@ void run() int main(int argc, char **argv) { - if (argc > 1) { - freopen(argv[1], "r", stdin); - } + printf("Input the brainfuck expression below\n"); init(); run(); return 0; -- cgit v1.2.3