S
Shutdownrunner
I want to store result of curl in a variable, which means to store a
webpage in a variable in order to parse it later and get our some useful
information. But unfortunately I'm not too experienced in C and I'm
making some stupid mistake. Could someone help me solve it?
#include <string.h>
#include <curl/curl.h>
size_t write_data(const char *buffer, size_t size, size_t nmemb, char
*userp)
{
char *string = userp;
size_t len;
len = size * nmemb;
strncat(string, buffer,len); // I get segfault here. Why????
return len;
}
int main(int argc, char **argv)
{
char *tablica="";
CURL *curl;
CURLcode success;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://debian.org/");//just a
sample url.
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, tablica);
success = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
Thanks in advance for your help.
webpage in a variable in order to parse it later and get our some useful
information. But unfortunately I'm not too experienced in C and I'm
making some stupid mistake. Could someone help me solve it?
#include <string.h>
#include <curl/curl.h>
size_t write_data(const char *buffer, size_t size, size_t nmemb, char
*userp)
{
char *string = userp;
size_t len;
len = size * nmemb;
strncat(string, buffer,len); // I get segfault here. Why????
return len;
}
int main(int argc, char **argv)
{
char *tablica="";
CURL *curl;
CURLcode success;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://debian.org/");//just a
sample url.
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, tablica);
success = curl_easy_perform(curl);
curl_easy_cleanup(curl);
}
return 0;
}
Thanks in advance for your help.