For wfopen on Linux and OS X, open the file name and mode (filename, mode) of the wide character version)
Wentao sun.
# Include <stdio. h>
# Include <wchar. h>
# Include <stdlib. h>
# Define max_path 1024
File * wfopen (const wchar_t * filename, const wchar_t * Mode)
{
Char FN [max_path];
Char M [max_path];
Wcstombs (FN, filename, max_path );
Wcstombs (M, mode, max_path );
Return fopen (FN, M );
}
# Define size 4
Struct person
{
Char name [10];
Int year;
Int month;
Int Day;
} Personarray [size];
Int main ()
{
Wchar_t * filename = l "/perforce/sandbox/1.txt ";
Wchar_t * mode = l "R ";
File * pfile = wfopen (filename, mode );
If (pfile)
Printf ("file open successeed! \ N ");
Else
Printf ("file open failed! \ N ");
/* Int I;
For (I = 0; I <size; I ++)
{
If (fread (& personarray [0], sizeof (struct person), I, pfile )! = 1)
{
Printf ("File Read failed at fread! \ N ");
}
}
Fclose (pfile );
For (I = 0; I <size; I ++)
{
Printf ("% s, % d", personarray [I]. Name, personarray [I]. Year, personarray [I]. Month,
Personarray [I]. Day );
Printf ("");
}
Printf ("\ n ");*/
/* Use the second test case to test */
Int C;
While (C = fgetc (pfile ))! = EOF)
{
Printf ("% C", C );
}
Fclose (pfile );
Return 0;
}