hi i'm trying to download a zip file from a website then save it under C:\\ (directory) but when the file has been downloaded, and when i open it, it seems incomplete, besides why do i need to write in the file, i just wanna download it then save it in such Directory.
#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>
#define download_path "C:\\data.zip"
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
size_t written;
written = fwrite(ptr, size, nmemb, stream);
return written;
}
int main(int argc, char** argv)
{
FILE *downloaded_file;
if ( (downloaded_file = fopen (download_path , "w" ) ) != NULL )
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se/download/curl-7.15.1-win32-ssl-sspi.zip");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, downloaded_file);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
if (res == CURLE_OK)
{
printf("Download complete!\n");
}
}
fclose(downloaded_file);
}
}