C++ File Updation
C++ File Updation
Usage:
The fopen function is used to open a file (identified by FILE structure).
Prototype:
FILE * fopen (const char * FileName, const char * Access);
Arguments:
Filename
Operating system name of the file, including path if necessary.
Access
One of the following character strings:
r
Open for reading (existing file only)
rb
Open for reading (existing file only) in binary mode
rt
Open for reading (existing file only) in text mode
r+
Open for update (existing file only)
rb+
Open for update (existing file only) in binary mode
rt+
Open for update (existing file only) in text mode
w
Open (or create) for writing (and delete any previous data)
wb
Open (or create) for writing (and delete any previous data) in binary mode
wt
Open (or create) for writing (and delete any previous data) in text mode
w+
Open (or create) for update (and delete any previous data)
wb+
Open (or create) for update (and delete any previous data) in binary mode
wt+
Open (or create) for update (and delete any previous data) in text mode
a
Open (or create) for append (and keep any previous data)
ab
Open (or create) for append (and keep any previous data) in binary mode
at
Open (or create) for append (and keep any previous data) in text mode
a+
Open (or create) for append update (and keep any previous data)
ab+
Open (or create) for append update (and keep any previous data) in binary mode
at+
Open (or create) for append update (and keep any previous data) in text mode
Header Files:
stdio.h
(fopen)
errno.h
(errno values)
Returns:
> 0
Pointer to an open FILE structure
NULL
Failure
Side Effect:
errno
Iff the open fails, the global variable errno is set to error code
EACCES
Permission denied
EINVACC
Invalid access mode
EMFILE
No file handle available
ENOENT
File or path not found
Example:
#include <stdio.h> . . . FILE * Account_Master; . . . Account_Master = fopen ("E:\DATA\ACCOUNTS.DAT", "ab+"); if (Account_Master == NULL) printf ("Open failed."); else printf ("Open succeeded.");