From the course: Complete Guide to C Programming Foundations
Unlock the full course today
Join today to access over 24,300 courses taught by industry experts.
Writing to a file - C Tutorial
From the course: Complete Guide to C Programming Foundations
Writing to a file
- [Instructor] To write to or create a file, you use the fopen function. The first argument is a file name string. The second argument, the mode, is either W for writing to a file or creating a new file for writing, or A for appending to a file that already exists. When the file doesn't exist, it's created and opened for writing. As with opening a file for reading, The fopen function returns a file handle, which is used with further file access functions. Data is written to a file using file versions of standard C output functions. These include fprint, fputc, fputs, and so on. These functions work like their standard IO counterparts, but with a file handle argument that indicates which open file the data is to be written to. When file writing is done, the fclose function closes the file. Do not forget this step. One of the duties of the fclose function is to complete writing data to the file, as some of the information may still be sitting in a buffer before it's actually written…
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)
-
-