简体   繁体   中英

Libcurl C - Save information Array

I am new using libcurl and I need some help for simple procedures.

I want my program to read information from a website, which will return the information in the following format:

   text | xxxxx | xxxxxxxxx
   text | xxxxx | xxxxxxxxx
   text | xxxxx | xxxxxxxxx

and I want to save that information into an array. Then read the information from the array, but only the second and third column, just the numbers to use them with another function.

I know how to get the information using libcurl in C from the website and I get it printed in the terminal window, but I do not know how to save it into an array. I am stuck there...

For example with this code: How would you save the information it returns into an array?

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
  CURL *curl;
  CURLcode res;


  curl = curl_easy_init();

  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http:www.example.com");
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

    /* Perform the request, res will get the return code */
    res = curl_easy_perform(curl);
    /* Check for errors */
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));

    /* always cleanup */
    curl_easy_cleanup(curl);
  }
  return 0;
}

I would appreciate any help I can get. Thank you.

Take a look at CURLOPT_WRITEFUNCTION option of curl_easy_setopt(), and follow their examples .

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

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_WRITEFUNCTION, write_callback); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM