Сравнить коммиты

...

7 Коммитов

Автор SHA1 Сообщение Дата
ba3805c7cd code: общее задание 4 2024-05-18 22:01:25 +03:00
438cacfdb1 code: почти работает 2024-05-18 20:29:57 +03:00
ed361dae03 code: ошибки curl 2024-05-18 15:06:31 +03:00
b9ccc72d62 code: easy_init 2024-05-18 14:54:36 +03:00
9e1fbe8dbe code: arg 2024-05-18 14:07:43 +03:00
54d52ef37d lib: подключение библиотек 2024-05-18 13:08:00 +03:00
d866ad8079 code: prompt 2024-05-18 12:24:44 +03:00

Просмотреть файл

@@ -1,4 +1,7 @@
#include <curl/curl.h>
#include <vector>
#include <sstream>
#include <string>
#include <iostream>
#include <string>
#include "histogram.h"
@@ -11,33 +14,64 @@ struct Input {
};
Input
input_data(istream& in) {
input_data(istream& in, bool prompt) {
size_t number_count;
cerr << "Enter number count: ";
if (prompt) {cerr << "Enter number count: ";};
in >> number_count;
Input in1;
in1.numbers.resize(number_count);
cerr << "Enter numbers: ";
if (prompt) {cerr << "Enter numbers: ";};
for (size_t i = 0; i < number_count; i++) {
in >> in1.numbers[i];
}
cerr << "Enter bin count: ";
if (prompt) {cerr << "Enter bin count: ";};
in >> in1.bin_count;
return in1;
}
int main()
{
const size_t SCREEN_WIDTH = 80;
const size_t MAX_ASTERISK = SCREEN_WIDTH - 3 - 1;
bool prompt = true;
auto in = input_data(cin);
auto bins = make_histogram(in.numbers, in.bin_count);
show_histogram_svg(bins);
return 0;
static size_t
write_data(void* items, size_t item_size, size_t item_count, void* ctx){
size_t data_size = item_size * item_count;
stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
buffer->write(reinterpret_cast<const char*>(items), data_size);
return data_size;
}
Input
download(const string& address){
stringstream buffer;
CURL *curl = curl_easy_init();
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, address.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
res = curl_easy_perform(curl);
if (res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
exit(1);
}
curl_easy_cleanup(curl);
}
return input_data(buffer, false);
}
int
main(int argc, char* argv[])
{
#include <curl/curl.h>
curl_global_init(CURL_GLOBAL_ALL);
Input input;
if (argc > 1) {
input = download(argv[1]);
} else {
input = input_data(cin, true);
}
const auto bins = make_histogram(input.numbers, input.bin_count);
show_histogram_svg(bins);
}