From the course: Exploring C Libraries
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Solution: Read and save a web page - C Tutorial
From the course: Exploring C Libraries
Solution: Read and save a web page
(upbeat electronic music) - [Instructor] My solution for this challenge uses code presented in this course to read and output text saved on a webpage. Here are the differences for this solution. In the main function, I've changed the address to reference the libcurl homepage. I've also added a file name buffer for the save operation as well as a file handle pointer. The rest of the operation proceeds as outlined in this course. The page.buffer is initialized. Easy curl is configured here followed by the options to set the address, activate FOLLOWLOCATION, assign the WRITEFUNCTION, and identify the storage page buffer. The fetch operation takes place, and any errors are dealt with. Easy curl then cleans itself up. Here's the new part, which is a file save operation. A file is open for writing, and any errors are dealt with here. The buffer is written to the file. A single fprintf statement handles the job. The file is closed, and along the way, the user is informed. The program ends…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.