From the course: Exploring C Libraries

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Saving web data

Saving web data - C Tutorial

From the course: Exploring C Libraries

Start my 1-month free trial

Saving web data

- Unless you direct it to do otherwise, text generated by the libcurl function curl_easy_perform is sent to standard output. You can, however, save the text to a file or redirect it to a buffer providing you set the proper libcurl options. So this code fetches information from a webpage and saves it to a file. The file is opened at line 14 by using standard C library functions. The libcurl easy interface is initialized at line 22, followed by various options. At line 26, the URL is specified. At line 32, the WRITEFUNCTION is set to the NULL pointer, which directs libcurl to look for a file handle, which is set at line 35. So the output it sent to the open file and not to standard output. The file opened is closed at line 48. And line 50 outputs a message to the user, otherwise the program runs successfully and would generate no output. Now, I've already compiled the program. So, we'll run it to see what it…

Contents