Hello,

I've been searching all around but I didn't found a link about this.

I want to get a html, and use like it was a .txt in fopen, so that I can read it.

Does anyone knows how to do this in C? I can use a .html in fopen but only if I manually save the page and specify the path where it is.

Since now thanks!

Recommended Answers

You can open any file with FILE*. It doesn't matter what the extension is. FILE* fp = fopen("name.html","r");

Jump to Post

All 2 Replies

You can open any file with FILE*. It doesn't matter what the extension is. FILE* fp = fopen("name.html","r");

Are you trying to read an HTML file from the web?

You may want to look at the curl library ( http://www.libcurl.org/ ). It will allow you to collect data directly from a URL in a pretty user-friendly fashion.

/* Downloads a webpage's html and saves it to a file 'out.html'. */
#include <curl/curl.h>
#include <stdio.h>
#include <stddef.h>

int main(void)
{
    CURL *c;
    FILE *f;
    
    f = fopen("out.html","w");

    c = curl_easy_init();
    curl_easy_setopt( c, CURLOPT_URL, "http://www.gnu.org/copyleft/gpl.html" );
    curl_easy_setopt( c, CURLOPT_WRITEDATA, f );
    curl_easy_perform( c );

    fclose( f );
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.