tags:

views:

60

answers:

3

Hello,

I want to get a HTML and use like a file in C. Actually I can do that, but I have to save the file first on the disk and then use fopen("/file.html", "r");. What I would like to do is to extract the html directly from the URL and work with it.

Hypothetically, fopen("http://www.google.com", "r");

I saw something about libcurl but i don't know if it will help me.

Can anyone help?

Since now thanks.

+3  A: 

You can do something as simple as:

#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.google.com");
    res = curl_easy_perform(curl);

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

Source: Using cURL in C

You can get the complete function documentations here: Using The libcurl C Interface

This PDF link will help you in using libcurl in VS

codaddict
+1  A: 

Yes, I think cURL would be a good choice.

http://stackoverflow.com/questions/2329571/c-libcurl-get-output-into-a-string

Devin Ceartas
A: 

libcurl should get you what you need. See the code sample here: http://curl.haxx.se/libcurl/c/fopen.html

This will allow you to "read remote streams instead of (only) local files".

ecounysis