From a04dd89365fcadf919bd486a75ba3e4f4629a45a Mon Sep 17 00:00:00 2001 From: SanJacobs Date: Tue, 12 Jul 2022 23:46:53 +0200 Subject: Made timeinput() vastly less tedious --- src/time.cpp | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) (limited to 'src/time.cpp') diff --git a/src/time.cpp b/src/time.cpp index 98a5482..1d087f8 100755 --- a/src/time.cpp +++ b/src/time.cpp @@ -317,14 +317,33 @@ int days_in(int month, int year) { } // TODO: Add checks for correct formatting, and ask for new input if wrong -moment timeinput(const moment) { - char input_string[5]; - std::cout << "Input time\nHHMM (24-hour format, no space)\n"; - std::cin >> input_string; - moment output{std::stoi(std::string(std::string(1, input_string[2])+input_string[3])), - std::stoi(std::string(std::string(1, input_string[0])+input_string[1])), - or_day, or_month, or_year}; - // This is retarded and needs to be completely replaced +moment timeinput(moment input_moment) { + char input_string[6]; + std::cout << "HH MM (24-hour format, use space)\n"; + std::cin.getline(input_string, 6); + + // This uglyness is just how you use strtok() to split a string, apparently + const char* p; + int split_input[2]; + int i{0}; + p = strtok(input_string, " "); + while (p != NULL) { + split_input[i] = int(atoi(p)); + i++; + p = strtok(NULL, " "); + } + + if((moment){split_input[1], split_input[0], + input_moment.day, input_moment.month, input_moment.year} < input_moment) + { + wind(input_moment, 0, 0, 1); + } + + std::cout << "Split 01: " << split_input[0] << std::endl; + std::cout << "Split 02: " << split_input[1] << std::endl; + + moment output{split_input[1], split_input[0], + input_moment.day, input_moment.month, input_moment.year}; return output; } -- cgit v1.2.1