Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //g++ get.c -o get `pkg-config --libs --cflags libcurl`
- //sudo aptitude install libcurl-dev
- #include <stdio.h>
- #include <curl/curl.h>
- #include <string>
- size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
- size_t written = fwrite(ptr, size, nmemb, stream);
- return written;
- }
- int main(void) {
- CURL *curl;
- FILE *fp;
- CURLcode res;
- char *url = "https://filmsbykris.com/v7/img/tux.png";
- char outfilename[FILENAME_MAX] = "tux.png";
- curl = curl_easy_init();
- if (curl) {
- fp = fopen(outfilename,"wb");
- curl_easy_setopt(curl, CURLOPT_URL, url);
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
- res = curl_easy_perform(curl);
- /* always cleanup */
- curl_easy_cleanup(curl);
- fclose(fp);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment