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

..

9 Коммитов

Автор 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
0bdf67a606 merging 2024-05-18 12:09:27 +03:00
97036095fa code: параметр in 2024-05-18 12:00:44 +03:00
3 изменённых файлов: 49 добавлений и 17 удалений

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

@@ -36,9 +36,7 @@
<Unit filename="histogram.h" />
<Unit filename="main.cpp" />
<Unit filename="svg.cpp" />
<Unit filename="svg.h">
<Option target="&lt;{~None~}&gt;" />
</Unit>
<Unit filename="svg.h" />
<Unit filename="text.cpp" />
<Unit filename="text.h" />
<Extensions>

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

@@ -1,5 +1,7 @@
#include <curl/curl.h>
#include <vector>
#include <sstream>
#include <string>
#include <iostream>
#include <string>
#include "histogram.h"
@@ -14,30 +16,62 @@ struct Input {
Input
input_data(istream& in, bool prompt) {
size_t number_count;
if (prompt) {cerr << "Enter number count: ";}
if (prompt) {cerr << "Enter number count: ";};
in >> number_count;
Input in1;
in1.numbers.resize(number_count);
if (prompt) {cerr << "Enter numbers: ";}
if (prompt) {cerr << "Enter numbers: ";};
for (size_t i = 0; i < number_count; i++) {
in >> in1.numbers[i];
}
if (prompt) {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, prompt);
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);
}

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

@@ -31,7 +31,7 @@
<Compiler>
<Add option="-Wall" />
</Compiler>
<Unit filename="histogram.cpp" />
<Unit filename="doctest.h" />
<Unit filename="unittest.cpp" />
<Extensions>
<lib_finder disable_auto="1" />