From 4d0f391a31bfc4df0c70af67bec99ada70b5f136 Mon Sep 17 00:00:00 2001 From: augustin64 Date: Fri, 27 Oct 2023 14:09:25 +0200 Subject: [PATCH] Add get_input --- Makefile | 2 +- src/include/config.h | 5 +++++ src/include/input.h | 6 ++++++ src/input.cpp | 27 +++++++++++++++++++++++++++ src/main.cpp | 2 ++ 5 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/include/config.h create mode 100644 src/include/input.h create mode 100644 src/input.cpp diff --git a/Makefile b/Makefile index 9ecb87f..f47f13c 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ CXXFLAGS = -Wall -Wextra -std=gnu99 -g -O3 # See memory leaks and Incorrect Read/Write # -fsanitize=address -lasan -$(BUILDDIR)/main: $(SRCDIR)/main.cpp +$(BUILDDIR)/main: $(SRCDIR)/main.cpp $(BUILDDIR)/input.o $(CXX) $^ -o $@ $(CFLAGS) $(LD_CFLAGS) diff --git a/src/include/config.h b/src/include/config.h new file mode 100644 index 0000000..c43e74e --- /dev/null +++ b/src/include/config.h @@ -0,0 +1,5 @@ +#ifndef DEF_CONFIG_H +#define DEF_CONFIG_H + + +#endif \ No newline at end of file diff --git a/src/include/input.h b/src/include/input.h new file mode 100644 index 0000000..cb9c695 --- /dev/null +++ b/src/include/input.h @@ -0,0 +1,6 @@ +#ifndef DEF_INPUT_H +#define DEF_INPUT_H + +string get_input(); + +#endif \ No newline at end of file diff --git a/src/input.cpp b/src/input.cpp new file mode 100644 index 0000000..e86fa10 --- /dev/null +++ b/src/input.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +#include "include/config.h" + + + +string get_input() { + string buffer; + string input = ""; + + int line_num = 0; + while (1) { + line_num++; + printf("%4d ", line_num); + getline(cin, buffer); + input += "\n" + buffer; + + int n = input.length(); + if (n >= 2 && input[n-1] == ';' && input[n-2] == ';') { + input[n-1] = '\0'; + break; + } + } + + return input; +} \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 5633c2c..51068a6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,8 @@ #include using namespace std; +#include "include/input.h" + int main(int argc, char* argv[]) { return 0;