Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6172205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:21:09+00:00 2026-05-23T23:21:09+00:00

I’ve really searched this. I’ve seen examples of how you can download and write

  • 0

I’ve really searched this. I’ve seen examples of how you can download and write data to a file with libcurl but I don’t know how to write them to an array

that’s the code I have so far:

static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
{

int written = fwrite(ptr, size, nmemb, (FILE *)stream);
return written;
}

int main(void)
{
CURL *curl_handle;
FILE *bodyfile;
static const char *headerfilename = "head.out";
FILE *headerfile;
static const char *bodyfilename = "body.out";

curl_global_init(CURL_GLOBAL_ALL);

/* init the curl session */
curl_handle = curl_easy_init();

/* set URL to get */
curl_easy_setopt(curl_handle, CURLOPT_URL,"http://example.com/");
/* no progress meter please */
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);

/* send all data to this function  */
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);

/* open the files */
headerfile = fopen(headerfilename,"w");
if (headerfile == NULL) {
    curl_easy_cleanup(curl_handle);
    return -1;
}
bodyfile = fopen(bodyfilename,"w");
if (bodyfile == NULL) {
    curl_easy_cleanup(curl_handle);
    return -1;
}

/* we want the headers to this file handle */
curl_easy_setopt(curl_handle,   CURLOPT_WRITEHEADER, headerfile);

/* we want the body to this file handle */
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, bodyfile);

/* get it! */
curl_easy_perform(curl_handle);

/* close the header file */
fclose(headerfile);
fclose(bodyfile);
return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:21:10+00:00Added an answer on May 23, 2026 at 11:21 pm

    It seems, what you need is described in the libcurl documentation:

    CURLOPT_WRITEFUNCTION

    Function pointer that should match the following prototype: size_t
    function( char *ptr, size_t size, size_t nmemb, void *userdata); This
    function gets called by libcurl as soon as there is data received that
    needs to be saved. […]

    That is you have to implement a function with the signature

    size_t my_array_write(char *ptr, size_t size, size_t nmemb, void *userdata);
    

    And pass it to curl:

    curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, my_array_write);
    

    However, I haven’t tested it (and I am not aware of a simpler way to achieve this). See the libcurl docs for more information.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how can I replace this 2 symbol below from the string
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I want to construct a data frame in an Rcpp function, but when I
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.