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: A blue square - C Tutorial
From the course: Exploring C Libraries
Solution: A blue square
(upbeat music) - [Instructor] Here is my solution, which borrows heavily from an exercise file presented earlier in this chapter. You know, the one that draws a big X on the image. Most of this code is the same, with only a few items changed. I've cleaned up some of the unused variables declared here. The image file names are updated to match the challenge. The blue pixel structure is added, as well as the size of the rectangle to draw. The rest of the code follows the chore of reading the images data into memory. The file is opened, the magic number is read, confirming that the file is valid. Storage and infrastructures are allocated here. Library functions read the image's data here, and the image info is extracted. The two key items are the image width and the image height, which are used to calculate where to set the blue square. This series of statements reads the data into memory buffers as described in the course. The input buffer is closed, and a final confirmation is made to…
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.