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

Manipulating files - C Tutorial

From the course: C: Data Structures, Pointers, and File Systems

Start my 1-month free trial

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…

Contents