Add get_input

This commit is contained in:
augustin64 2023-10-27 14:09:25 +02:00
parent ba9d670ebd
commit 4d0f391a31
5 changed files with 41 additions and 1 deletions

View File

@ -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)

5
src/include/config.h Normal file
View File

@ -0,0 +1,5 @@
#ifndef DEF_CONFIG_H
#define DEF_CONFIG_H
#endif

6
src/include/input.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef DEF_INPUT_H
#define DEF_INPUT_H
string get_input();
#endif

27
src/input.cpp Normal file
View File

@ -0,0 +1,27 @@
#include <iostream>
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;
}

View File

@ -1,6 +1,8 @@
#include <iostream>
using namespace std;
#include "include/input.h"
int main(int argc, char* argv[]) {
return 0;