curl-library
Re: why is file size 0?
Date: Mon, 13 Apr 2009 07:21:24 +0000
in this code there is an error
double size;
CURL *session;
CURLcode result;
session = curl_easy_init();
curl_easy_setopt(session, CURLOPT_NOBODY, 1);
curl_easy_setopt(session, CURLOPT_URL, url);
curl_easy_setopt(session, CURLOPT_VERBOSE, 1);
result = curl_easy_perform(session);
curl_easy_getinfo(session, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &size);
if (result != CURLE_OK) {
fprintf(stderr, "Unable to get size of %s\n", hex);
goto abort;
}
fprintf(stdout, "size is %d\n", size);
curl_easy_cleanup(session);
in last fprintf function we must give a pecifier (%f) for double not
(%d) for decimal
Code will be :
double size;
CURL *session;
CURLcode result;
session = curl_easy_init();
curl_easy_setopt(session, CURLOPT_NOBODY, 1);
curl_easy_setopt(session, CURLOPT_URL, url);
curl_easy_setopt(session, CURLOPT_VERBOSE, 1);
result = curl_easy_perform(session);
curl_easy_getinfo(session, CURLINFO_CONTENT_LENGTH_DOWNLOAD, &size);
if (result != CURLE_OK) {
fprintf(stderr, "Unable to get size of %s\n", hex);
goto abort;
}
fprintf(stdout, "size is %.2f\n", size);
curl_easy_cleanup(session);
Received on 2009-04-13