#include <wchar.h>
|
FILE *
wfopen (const wchar_t * restrict path, const wchar_t * restrict mode); |
The argument mode points to a string beginning with one of the following sequences (Additional characters may follow these sequences.):
"r" | Open text file for reading. The stream is positioned at the beginning of the file. |
"r+" | Open for reading and writing. The stream is positioned at the beginning of the file. |
"w" | Truncate to zero length or create text file for writing. The stream is positioned at the beginning of the file. |
"w+" | Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file. |
"a" | Open for writing. The file is created if it does not exist. The stream is positioned at the end of the file. Subsequent writes to the file will always end up at the then current end of file, irrespective of any intervening fseek or similar. |
"a+" | Open for reading and writing. The file is created if it does not exist. The stream is positioned at the end of the file. Subsequent writes to the file will always end up at the then current end of file, irrespective of any intervening fseek or similar. |
The mode string can also include the letter ‘‘b’’ either as a third character or as a character between the characters in any of the two-character strings described above. This is strictly for compatibility with -isoC and has no effect; the ‘‘b’’ is ignored.
Reads and writes may be intermixed on read/write streams in any order, and do not require an intermediate seek as in previous versions of stdio. This is not portable to other systems, however; ANSI C requires that a file positioning function intervene between output and input, unless an input operation encounters end-of-file.
/****************** this program shows opening in write mode,write data and close **************/ /****************** again open in append mode and write data***** ******************************/ /***************************** Check file c:\wfopen.txt*****************************************/ #include <stdio.h> int main(void) { FILE *fp; wchar_t* name = L"c:\wfopen.txt"; if ((fp = wfopen (name, L"wb")) == NULL) { printf("Error creating file"); return -1; } printf("Opened file \n"); fprintf(fp, "This is the first line\n"); printf("Wrote to file\n"); fclose (fp); printf("Closed file\n"); if ((fp = wfopen (name, L"a")) == NULL) { printf("Error opening file"); return -1; } printf("Opened file for appending\n"); fprintf(fp, "This is the second line\n"); fclose (fp); printf("closed file, check output in c:\ wfopen.txt file\n"); wunlink(name); return 0; }
Output
Opened file Wrote to file Closed file Opened file for appending closed file, check output in c:\ wfopen.txt file
[EINVAL] | |
The mode argument to wfopen, was invalid. | |
The wfopen, functions may also fail and set errno for any of the errors specified for the routine malloc.
The wfopen function may also fail and set errno for any of the errors specified for the routine wopen.
1) Mode values for group and others will be ignored for file creation, execute bit and setuid on exec bit on an file don’t
have any effect while file creation.Default working
directoy of a process is initalized to C:
rivate
ID (UID of the calling application), and any data written into this C:
rivate
ID directory persists between phone resets.
2) If the specified file is a symbolic link and the file it is pointing to is invalid, the symbolic link file will be automatically removed.
© 2005-2007 Nokia |