I write a program with libcurl.
#include <stdio.h>
#include <string.h>
#include <curl/curl.h>
#define URL_MAX 256
int main(int argc, char *args[])
{
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
curl_easy_setopt(curl, CURLOPT_URL, args[1]);
curl_easy_perform(curl);
curl_easy_cleanup(curl);
return 0;
}
$ gcc tinyCurl.c
$ gcc curl-config --libs
tinyCurl.c
$ ./a.out http://example.com/
I examine search it google but I can't find .
I want to store char[] not stdout.
Is a question of the beginner thanking you in advance
Check out the
curl_easy_setopt()
function.You would want to register a callback using
CURLOPT_WRITEFUNCTION
- this callback would be called whenever data is received. From within the callback you could do whatever you want with the data.Note - this is somewhat tricky stuff for a beginner. You need to understand what function pointers are.
(this answer is based on reading the API in http://curl.haxx.se/libcurl/c/curl_easy_setopt.html - I have never used libcurl).
EDIT -
Here is an example found by googling for
CURLOPT_WRITEFUNCTION
, in the curl-library mailing list. This example is by Daniel Stenberg.I get it !
Thank you Hexagon.