From c3dfd48d9c496ddb110644aef94ef53ec2012293 Mon Sep 17 00:00:00 2001 From: YaroslavS Date: Sun, 25 May 2025 21:10:46 +0300 Subject: [PATCH] =?UTF-8?q?=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20?= =?UTF-8?q?=D1=81=20=D0=B1=D1=83=D1=84=D0=B5=D1=80=D0=BE=D0=BC,=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B3=D1=80=D1=83=D0=B6=D0=B5=D0=BD=D0=BD=D1=8B=D0=BC=20?= =?UTF-8?q?=D0=BF=D0=BE=20=D1=81=D0=B5=D1=82=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Histogram/main.cpp | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/Histogram/main.cpp b/Histogram/main.cpp index 69d5d96..0f6d8c4 100644 --- a/Histogram/main.cpp +++ b/Histogram/main.cpp @@ -1,10 +1,12 @@ #include #include -#include "histogram.h" -#include "text.h" #include #include #include +#include + +#include "histogram.h" +#include "text.h" struct Input{ std::vector numbers; size_t bin_count{}; @@ -36,32 +38,39 @@ Input input_data(std::istream& in, bool prompt) { return result; }; +Input download(const std::string&address){ + std::stringstream buffer; + CURL* curl = curl_easy_init(); + if(curl) { -using namespace std; - -int main(int argc, char* argv[]) { - curl_global_init(CURL_GLOBAL_ALL); - if (argc>1){ - - CURL *curl = curl_easy_init(); + CURLcode res; + curl_easy_setopt(curl, CURLOPT_URL, address.c_str()); - if(curl) { + TODO: - CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, argv[1]); res = curl_easy_perform(curl); if (res != CURLE_OK){ - cerr << curl_easy_strerror(res); + std::cerr << curl_easy_strerror(res); + curl_easy_cleanup(curl); exit(1); } curl_easy_cleanup(curl); } - return 0; + return input_data(buffer, false); +} +using namespace std; + +int main(int argc, char* argv[]) { + curl_global_init(CURL_GLOBAL_ALL); + Input input; + if (argc > 1) { + input = download(argv[1]); + } else { + input = input_data(cin, true); } - Input in = input_data(std::cin, true); - auto bins = make_histogram(in.numbers, in.bin_count); + const auto bins = make_histogram(input.numbers, input.bin_count); show_histogram_svg(bins); return 0; }