diff --git a/main.cpp b/main.cpp index 01d834a..67bfa4a 100644 --- a/main.cpp +++ b/main.cpp @@ -31,6 +31,13 @@ Input input_data(istream& in, bool prompt = true) cerr << "Enter bin count: "; in >> input.bin_count; return input; +} + 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(ctx); + (*buffer).write(reinterpret_cast(items), data_size); + return data_size; } Input download(const string& address) { @@ -39,6 +46,8 @@ download(const string& address) { 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){ cerr << curl_easy_strerror(res); @@ -51,15 +60,15 @@ download(const string& address) { int main(int argc, char* argv[]) { + bool show_prompts; + cout << "Show prompts? (1 for yes, 0 for no): "; + cin >> show_prompts; Input input; if (argc > 1) { input = download(argv[1]); } else { input = input_data(cin, true); } - bool show_prompts; - cout << "Show prompts? (1 for yes, 0 for no): "; - cin >> show_prompts; const auto bins = make_histogram(input.numbers, input.bin_count); show_histogram_svg(bins); }