Need help to get an html and use in C like a text file in fopen

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.

Answers


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


Yes, I think cURL would be a good choice.

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


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".


Need Your Help

How to check Windows edition in Java?

java windows windowsversion

I want to check Windows edition (Basic or Home or Professional or Business or other) in Java.

Way to automate deletion of expired records in MySQL?

mysql

I've googled around and searched the MYSQL docs ad nauseam and couldn't find a succinct way of automating deletion of records that exceeded a given timeframe. I've been able to get a query in 5.1 t...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.