Cant write file I downloaded using curl in C -


i have c code using curl want use download csv file. when use though, instead of getting , writing file disk, writes html of webpage or doesnt write @ all. here code:

size_t my_write_func(void *ptr, size_t size, size_t nmemb, file *stream) {     return fwrite(ptr, size, nmemb, stream); }  void *downloadfile(void *ptr) {     curl *curl;     curlcode res;     file *outfile;     char *symbol = (char *)ptr;      curl = curl_easy_init();     if(curl)     {         outfile = fopen(symbol, "w");         char url[100] = "http://finance.yahoo.com/d/quotes.csv?s=";         strcat(url, symbol);         strcat(url, "&f=npl1");         curl_easy_setopt(curl, curlopt_url, url);         curl_easy_setopt(curl, curlopt_writedata, outfile);         curl_easy_setopt(curl, curlopt_writefunction, my_write_func);          res = curl_easy_perform(curl);         curl_easy_cleanup(curl);         fclose(outfile);     } } 

as wrote on official doc :

the internal default function write data file * given curlopt_writedata.

so, app, don't need make callback function.

void *downloadfile(void *ptr) {     curl *curl;     curlcode res;     file *outfile;     char *symbol = (char *)ptr;      curl = curl_easy_init();     if(curl)     {         outfile = fopen(symbol, "w");         char url[100] = "http://finance.yahoo.com/d/quotes.csv?s=";         strcat(url, symbol);         strcat(url, "&f=npl1");         curl_easy_setopt(curl, curlopt_url, url);         curl_easy_setopt(curl, curlopt_writedata, outfile);          res = curl_easy_perform(curl);         curl_easy_cleanup(curl);         fclose(outfile);     } } 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -