#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
size_t write_callback(void *data, size_t size, size_t nmemb, void *userp)
{
size_t realsize = size * nmemb;
memcpy(userp, data, realsize);
return realsize;
}
int main(void)
{
CURL *curl;
CURLcode res;
char *buf;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if (curl)
{
curl_easy_setopt(curl, CURLOPT_URL, "https://curl.se/");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)buf);
res = curl_easy_perform(curl);
if (res != CURLE_OK)
{
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
printf("%s", buf);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return EXIT_SUCCESS;
}