From 482544ef8ce3d23326f958dc6aa848517159bafe Mon Sep 17 00:00:00 2001 From: 1computer1 Date: Mon, 3 Jun 2019 19:00:06 -0400 Subject: [PATCH] Fix Brainfuck input --- docker/brainfuck/bf.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/docker/brainfuck/bf.cpp b/docker/brainfuck/bf.cpp index 048ce19..acb83bc 100644 --- a/docker/brainfuck/bf.cpp +++ b/docker/brainfuck/bf.cpp @@ -1,18 +1,28 @@ #include #include #include +#include int main(int argc, char **argv) { + std::string ops; if (argc == 1) { - std::cerr << "No input given"; - return 1; + std::string line; + while (std::getline(std::cin, line)) { + ops.append(line); + } + + if (ops.empty()) { + std::cerr << "No input given"; + return 1; + } + } else { + ops.assign(argv[1], strlen(argv[1])); } - char *ops = argv[1]; + int len = ops.length(); std::vector tape = { 0 }; int oix = 0; int tix = 0; - int len = strlen(ops); while (oix < len) { switch (ops[oix]) { case '>':