Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Apple Xcode
- // download file from web
- // gcc -lcurl main.c -o teste
- //#define CURL_STATICLIB
- #include <stdio.h>
- #include <curl/curl.h>
- size_t func_write_data(void *the_ptr, size_t the_size, size_t the_nmemb, FILE *the_stream)
- {
- size_t the_written = fwrite(the_ptr, the_size, the_nmemb, the_stream);
- return the_written;
- }
- int main (int argc, const char * argv[])
- {
- // realiza o download de um ficheiro da web para o computador
- CURL *the_curl;
- FILE *the_file;
- CURLcode the_curl_code;
- char *the_url = "http://elmicro.com/files/cosmic/clanguage.pdf";
- char the_output_file[FILENAME_MAX] = "/Users/.../Desktop/clanguage.pdf";
- the_curl = curl_easy_init();
- if (the_curl)
- {
- the_file = fopen(the_output_file, "wb");
- curl_easy_setopt(the_curl, CURLOPT_URL, the_url);
- curl_easy_setopt(the_curl, CURLOPT_WRITEFUNCTION, func_write_data);
- curl_easy_setopt(the_curl, CURLOPT_WRITEDATA, the_file);
- the_curl_code = curl_easy_perform(the_curl);
- curl_easy_cleanup(the_curl);
- fclose(the_file);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment