From the course: Complete Guide to C Programming Foundations
Unlock the full course today
Join today to access over 24,500 courses taught by industry experts.
Chapter solution: Managing files - C Tutorial
From the course: Complete Guide to C Programming Foundations
Chapter solution: Managing files
(bright music) - [Instructor] Here is my solution to the chapter challenge starting with the create_file function. The file name is passed as constant character f. It's opened at line 10, line 11 tests for an error. If so, an error message is output and the program quits. Otherwise, a success message is output at line 16. Remember to output the success messages, otherwise, the code runs quietly and the user may not think anything is happening. Line 19 writes my name to the file. The printf statement sends the text to the file, opened as file handle fh. Then a text message is output confirming the operation. The file is closed. Again, a text message outputs success. Your function need not read exactly as shown here, but it must contain all of the steps. To confirm that the file was written, the read file function reads in the string. A buffer is required, which is declared at line 30. You see, I use the same size 32, so I could have set this size as a constant. I chose not to. The file…
Contents
-
-
-
-
-
-
-
-
-
-
-
(Locked)
Reading from a file3m 31s
-
(Locked)
Writing to a file3m 40s
-
(Locked)
Challenge: Writing and reading files1m
-
(Locked)
Solution: Writing and reading files4m 4s
-
(Locked)
Working with raw data3m 4s
-
(Locked)
Using random file access3m 21s
-
(Locked)
Challenge: Access database records56s
-
(Locked)
Solution: Access database records2m 51s
-
(Locked)
Manipulating files2m 34s
-
(Locked)
Exploring the path1m 50s
-
(Locked)
Reading a directory3m 36s
-
(Locked)
Getting file information3m 26s
-
(Locked)
Chapter challenge: Managing files1m 46s
-
(Locked)
Chapter solution: Managing files2m 50s
-
(Locked)
-
-