diff --git a/project/main.cpp b/project/main.cpp index 612e3bf..a9c7371 100644 --- a/project/main.cpp +++ b/project/main.cpp @@ -31,7 +31,10 @@ input_data(istream& in, bool promt) { in >> ik.numbers[i]; } - cerr << "Enter bin count: "; + if (promt) + { + cerr << "Enter bin count: "; + } in>> ik.bin_count; return ik; } @@ -40,8 +43,8 @@ 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(static_cast(items), data_size); - return 0; + buffer->write(reinterpret_cast(items), data_size); + return data_size; } @@ -53,18 +56,18 @@ download(const string& address) if(curl) { CURLcode res; - curl_easy_setopt(curl, CURLOPT_URL, address); + 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); - curl_easy_cleanup(curl); if (res != CURLE_OK) { fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res)); exit(1); } - } - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); + curl_easy_cleanup(curl); + } return input_data(buffer, false); }