From 7088f781d6373b8492d3cd62b79ade7c5bcbc395 Mon Sep 17 00:00:00 2001 From: RyabovAS Date: Sun, 30 Jun 2024 20:06:56 +0300 Subject: [PATCH] =?UTF-8?q?code:=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D1=91?= =?UTF-8?q?=D0=BD=20=D0=BA=D0=BE=D0=B4=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80?= =?UTF-8?q?=D0=B0=D0=BC=D0=BC=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index c0d006d..1e09620 100644 --- a/main.cpp +++ b/main.cpp @@ -2,7 +2,9 @@ #include #include #include "histogram.h" - +#include +#include +#include using namespace std; struct Input { @@ -10,6 +12,10 @@ struct Input { size_t bin_count{}; }; +static size_t write_callback(void *ptr, size_t size, size_t nmemb, void *userdata) { + return size * nmemb; +} + Input input_data(istream& in){ size_t number_count; @@ -22,12 +28,43 @@ in >> cin.bin_count; return cin; } -int main(int argc, char* argv[]){ -// curl_global_init(CURL_GLOBAL_ALL); -if(argc>1){ - cout<(ctx); + (*buffer).write(items, data_size); return 0; } + + +int main(int argc, char* argv[]){ +curl_global_init(CURL_GLOBAL_ALL); +CURL *curl = curl_easy_init(); +if(curl) { + curl_easy_setopt(curl, CURLOPT_URL, "http://uit.mpei.ru/study/courses/cs/lab03/marks.txt"); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback); + curl_easy_perform(curl); + double speed; + curl_easy_getinfo(curl, CURLINFO_SPEED_DOWNLOAD, &speed); + printf("Скорость загрузки файла: %.2f bytes/sec", speed); + curl_easy_cleanup(curl); +} + Input input; + if (argc > 1) { + input = download(argv[1]); + } else { + input = input_data(cin, true); + } auto in = input_data(cin); auto bins = make_histogram(in.numbers, in.bin_count); show_histogram(bins, in.bin_count);