From the course: C: Data Structures, Pointers, and File Systems
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Manipulating files - C Tutorial
From the course: C: Data Structures, Pointers, and File Systems
Manipulating files
- If you're creating files in C you might also want to know how to manipulate them. The C library comes with two file manipulation functions, rename to rename a file and unlink to remove a file and if you need more file manipulation functions, you can write your own. The rename function seems like it should be more involved, but it's not. Prototyped in the STDIO.H header file it requires two arguments as shown at line seven, the original file and its new name. These strings can also be expressed as full path names. Here I'm renaming alpha.txt which is included in the exercise files, to a.txt. If the value returned as zero the operation was successful. Build and run, and the operation was successful. And I can check in the folder window and this was alpha.txt now it's a.txt. Be aware that the file must be in the same folder where you were in the program for the renaming operation to work, otherwise you have to specify a full path name in the function. To delete a file you use the…
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.
Contents
-
-
-
-
-
-
Reading from a file3m 25s
-
(Locked)
Writing to a file3m 24s
-
(Locked)
Working with raw data2m 53s
-
(Locked)
Using random file access2m 47s
-
(Locked)
Manipulating files2m 57s
-
(Locked)
Exploring the path2m 8s
-
(Locked)
Reading a directory2m 53s
-
(Locked)
Getting file information2m 46s
-
(Locked)
Using command line arguments2m 44s
-
(Locked)
Calling the operating system2m 46s
-
(Locked)
Challenge: Read and store filenames1m 6s
-
(Locked)
Solution: Read and store filenames2m 52s
-
-
-