diff --git a/ex00/src/BitcoinExchange.cpp b/ex00/src/BitcoinExchange.cpp index 791fe22..3fe24e1 100644 --- a/ex00/src/BitcoinExchange.cpp +++ b/ex00/src/BitcoinExchange.cpp @@ -49,7 +49,7 @@ static int check_date(const std::string& line, unsigned int& out) mounth = std::atoi(line.substr(5).c_str()); day = std::atoi(line.substr(8).c_str()); - if (date_is_valid(day, mounth, year)) + if (!date_is_valid(day, mounth, year)) return 1; out = year * 10000 + mounth * 100 + day; return 0; @@ -79,7 +79,7 @@ static int check_value(const std::string& value_str, int flag, float& out) static int check_line(const std::string& line, regex_t& reegex, const std::string& delimiter, int flag, std::pair& out) { - if (line == std::string("date") + delimiter + std::string(flag == DATABASE ? "exchange_rate" : "value")) + if (line == std::string("date") + delimiter + (flag == DATABASE ? "exchange_rate" : "value")) return 1; if (regexec(&reegex, line.c_str(), 0, NULL, 0) == REG_NOMATCH) { @@ -88,8 +88,10 @@ static int check_line(const std::string& line, regex_t& reegex, const std::strin } unsigned int date; if (check_date(line, date)) + { + std::cout << "Error: bad input => " << line << std::endl; return 1; - + } float value; if (check_value(line.substr(10 + delimiter.length()), flag, value)) return 1; @@ -106,7 +108,7 @@ static int get_data(std::map& out) if (!file.good()) { - std::cout << "error: file: " << "data.csv" << std::endl; + std::cout << "Error: could not open file." << std::endl; return 1; } @@ -114,7 +116,7 @@ static int get_data(std::map& out) if (regcomp(&reegex, DATA_PATERN, REG_EXTENDED)) { - std::cout << "regex compilation fail" << std::endl; + std::cout << "Error: regex compilation fail." << std::endl; return 1; } @@ -185,11 +187,8 @@ static int get_input(const std::string& file_path, const std::map database; - - if (db_init == 0) - get_data(database); + std::map database; + get_data(database); get_input(file_path, database); } diff --git a/ex00/src/main.cpp b/ex00/src/main.cpp index 3a4ec4d..c872ac4 100644 --- a/ex00/src/main.cpp +++ b/ex00/src/main.cpp @@ -5,7 +5,7 @@ int main(int ac, char** av) { if (ac != 2) { - std::cout << "error: missing file" << std::endl; + std::cout << "error: could not open file." << std::endl; return 1; } get_price(std::string(av[1]));