The C library comes with file manipulation functions to rename a file, rename(), and to delete a file, unlink(). The rename() function is given two arguments, the path name of the original file and the new name string. The unlink() function removes the named file. The C library lacks a function to copy a file, though you can write your own. Open the original file for reading and the duplicate for writing.
- 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. …
- Working with arrays
- Building a structure
- Creating an array of structures
- Testing characters
- Working with strings in C
- Using pointers to manipulate data
- Manipulating files
- Using command-line arguments
- Working with time functions
Skill Level Intermediate
1. Arrays and Structures
2. Characters and Strings
4. Files and the Operating System
5. The Interesting and Extraordinary
Next steps1m 52s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.