code: код выполнен до индивидуальных заданий

master
MakhnovGA 2 лет назад
Родитель 6e1d4011cf
Сommit b2f21d03de

@ -13,11 +13,10 @@
<Option compiler="gcc" /> <Option compiler="gcc" />
<Compiler> <Compiler>
<Add option="-g" /> <Add option="-g" />
<Add directory="curl/include" /> <Add directory="C:/Users/gmack/OneDrive/Рабочий стол/lab01/lab_01/curl/include" />
</Compiler> </Compiler>
<Linker> <Linker>
<Add library="libcurl.dll.a" /> <Add library="curl/lib/libcurl.dll.a" />
<Add directory="curl/lib" />
</Linker> </Linker>
</Target> </Target>
<Target title="Release"> <Target title="Release">

@ -10,7 +10,7 @@
1682341619 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram.h 1682341619 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\histogram.h
<vector> <vector>
1684761978 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\main.cpp 1685882470 source:c:\users\gmack\onedrive\ðàáî÷èé ñòîë\lab01\lab_01\main.cpp
<math.h> <math.h>
<iostream> <iostream>
<conio.h> <conio.h>
@ -20,6 +20,8 @@
"svg.h" "svg.h"
"histogram_internal.h" "histogram_internal.h"
<curl/curl.h> <curl/curl.h>
<sstream>
<string>
1681931523 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\text.h 1681931523 c:\users\gmack\onedrive\đŕáî÷čé ńňîë\lab01\lab_01\text.h
<vector> <vector>

@ -2,24 +2,24 @@
<CodeBlocks_layout_file> <CodeBlocks_layout_file>
<FileVersion major="1" minor="0" /> <FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" /> <ActiveTarget name="Debug" />
<File name="text.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="histogram.h" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="73" topLine="0" /> <Cursor1 position="167" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="text.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="histogram_internal.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="211" topLine="0" /> <Cursor1 position="173" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="svg.h" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="svg.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="106" topLine="0" /> <Cursor1 position="980" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="svg.cpp" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="-1" zoom_2="0"> <File name="text.h" open="0" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="980" topLine="0" /> <Cursor1 position="73" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="histogram.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="histogram.cpp" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
@ -27,19 +27,19 @@
<Cursor1 position="1502" topLine="23" /> <Cursor1 position="1502" topLine="23" />
</Cursor> </Cursor>
</File> </File>
<File name="histogram_internal.h" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="main.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="173" topLine="0" /> <Cursor1 position="725" topLine="7" />
</Cursor> </Cursor>
</File> </File>
<File name="histogram.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="svg.h" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="167" topLine="0" /> <Cursor1 position="106" topLine="0" />
</Cursor> </Cursor>
</File> </File>
<File name="main.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0"> <File name="text.cpp" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor> <Cursor>
<Cursor1 position="811" topLine="0" /> <Cursor1 position="211" topLine="0" />
</Cursor> </Cursor>
</File> </File>
</CodeBlocks_layout_file> </CodeBlocks_layout_file>

@ -39,39 +39,31 @@ input_data(istream &tin, bool prompt){
size_t size_t
write_data(void* items, size_t item_size, size_t item_count, void* ctx) { write_data(void* items, size_t item_size, size_t item_count, void* ctx) {
CURL* curl = curl_easy_init();
if(curl) {
CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
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);
}
size_t data_size = item_size * item_count; size_t data_size = item_size * item_count;
return 0; stringstream* buffer = reinterpret_cast<stringstream*>(ctx);
buffer->write(reinterpret_cast<const char*>(items), data_size);
return data_size;
} }
Input Input
download(const string& address) { download(const string& address) {
stringstream buffer; stringstream buffer;
CURL* curl = curl_easy_init(); CURL *curl = curl_easy_init();
if(curl) { if(curl)
{
CURLcode res; CURLcode res;
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com"); 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); res = curl_easy_perform(curl);
if(res != CURLE_OK){ if (res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n", {
curl_easy_strerror(res)); fprintf(stderr, "curl_easy_perform() failed: %s\n",curl_easy_strerror(res));
exit(1); exit(1);
} }
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_cleanup(curl); curl_easy_cleanup(curl);
}
}
return input_data(buffer, false); return input_data(buffer, false);
} }

Загрузка…
Отмена
Сохранить