cURL / Mailing Lists / curl-library / Single Mail

curl-library

Saving html's to disk

From: Michael Swan <michael_swan_at_optusnet.com.au>
Date: Sun, 16 Oct 2005 22:36:31 +1000

Hi,

I can't see where the error is below. It crashes when it tries to save the data to the file I gave it. Is this the right way to do it ?

#include <stdio.h>

#include ".\include\curl/curl.h"

int main(void)

{

CURL *curl;

CURLcode res;

curl = curl_easy_init();

if(curl)

{

FILE *f ;

if ( (f = fopen("test.html","w+t")) != NULL)

{

// set the file to write

curl_easy_setopt(curl, CURLOPT_WRITEDATA,f);

// I think this needs to be null

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION , NULL);

curl_easy_setopt(curl, CURLOPT_VERBOSE, 1);

curl_easy_setopt(curl, CURLOPT_URL, "http://curl.haxx.se");

// Crashes here

res = curl_easy_perform(curl);

/* always cleanup */

curl_easy_cleanup(curl);

fclose(f);

}

}

return 0;

}

No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.344 / Virus Database: 267.12.0/134 - Release Date: 14/10/2005
Received on 2005-10-16