Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

Read All File Contents Into A Dynamically Allocated String | C Programming Example

12.3K views on YouTube

How to read and store all the contents of a file into a dynamically allocated string using C. An optimized solution that only requires reading the file once is created, after first creating a suboptimal but easier to understand solution that requires reading the file twice. A simple performance test is conducted to demonstrate the improved performance of the optimized solution.

Source code for the optimized solution: https://github.com/portfoliocourses/c-example-code/blob/main/file_to_dynamic_string_optimized.c

Source code for the suboptimal solution: https://github.com/portfoliocourses/c-example-code/blob/main/file_to_dynamic_string_suboptimal.c

Check out https://www.portfoliocourses.com to build a portfolio that will impress employers!