CSO101: Computer Programming
Lecture – 29
O.S.L. Bhavana
Files
Files
Files
Files: fopen
Files
Files: fclose
fclose :
Files
Files
Practice
Write a program that reads all characters of a file and writes these characters in reverse order to a new file.
File Modes
Mode | Operations |
“r” | Reading from a file – sets up a pointer to the first character in it |
“w” | Writing to a file. If the file already exists the file will be over-written, else a file with the name will be created |
“a” | Opens a file for writing and sets up a pointer to the last character in it. If the file doesn’t exist a new file will be created. Used to append contents at the end of a file |
“r+” | Reading existing content, writing new content, modifying existing content |
“w+” | Writing new content, reading the new content and modifying existing contents of file |
“a+” | Reading existing content, appending new content at the end of file – cannot modify existing content |
Reference: Let us C
fopen returns a null pointer if the file cannot be opened (irrespective of the mode)
File Modes